Announcement

Collapse
No announcement yet.

Batch file to edit a txt file that is part of a compiled exe file using for /f

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch file to edit a txt file that is part of a compiled exe file using for /f

    i have a compiled executable that runs a certain input file, and provides a certain output file.

    I need to conduct analysis of multiple inputs and versus multiple outputs

    i will need to run the exe about 100 times but the only difference in each input is a single number

    i just started writing batch files, and i have figured out a way to run the executable, and change the variable in the input

    i am having trouble making the batch file continuously run the program while changing the input variable by adding 1 from 24 to 25.

    Below is a test series that i have been using to learn, i have been doing this for weeks, and unfortunately no one around here has a clue about what i am talking about. this is really important. Can you help me?

    Code:
    : BEGIN
    :: (THIS IS THE EXECUTABLE)
    ..executabl.exe  
    :: (THIS IS WHERE THE OUTPUT FILE IS BEING SAVED)
    @ECHO OFF
    COPY out.TXT out1.TXT 
    :: (THIS IS where THE VARIABLE IN THE input FILE IS BEING CHANGED FROM 24 TO 25)
    SETLOCAL ENABLEDELAYEDEXPANSION
    FOR /F "tokens=*delims=" %%a in (inp.txt) do (set str=%%a
    set str=!str:24=25! 
    ECHO !str!>> inp.TXT
    :: (THIS IS WHERE I GET STUCK, I NEED TO PROGRAM TO RUN WITH VALUES OF !str! from 24 to 100)
    IF !str!==100 GOTO END
    IF NOT GOTO BEGIN)
    : END
    Last edited by Rems; 27th June 2010, 20:52.

  • #2
    Re: Batch file to edit a txt file that is part of a compiled exe file using for /f

    Im having a little trouble reading your code

    Might be me or maybe I dont understand exactly what you are trying to do.
    If you just need a number to run as input like 1 to 25 use the for /l command.

    FOR /L %variable IN (start,step,end) DO command [command-parameters]

    Please be specific in what you want to accomplish.
    Why is there a " delimiter is your text file '"' delimited ?
    Please give points where appropriate

    <I dont create ready scripts for you, but I'm willing to point you in the right direction>

    Comment


    • #3
      Re: Batch file to edit a txt file that is part of a compiled exe file using for /f

      If you can control the name of the output file and control the name of the copied file, would using SHIFT be any use?
      A recent poll suggests that 6 out of 7 dwarfs are not happy

      Comment


      • #4
        Re: Batch file to edit a txt file that is part of a compiled exe file using for /f

        Here you go
        Code:
        @echo off & cls
        
        Set /a iStart = 24
        Set /a iStop = 100
        
        (For /L %%! in (%iStart%,1,%iStop%) do call:RunExe %%!) & goto :endLoop
        
        :RunExe / begin of Loop
        If exist out.TXT REN out.TXT out%1.TXT
        
        :: (THIS IS THE EXECUTABLE)
        echo.Running: %1 of %iStop%
        START ""/MIN executable.exe
        echo.
        
        set /a iNext = %1 + 1
        If %iNext%0 GTR %iStop%0 exit /b 0
        
        FOR /F "UsebackQ delims=" %%* in ("inp.txt") do set str=%%*
        >>"inp.txt" call echo.%%str:%1=%iNext%%%
        exit /b 0
        
        :endLoop
        You didn't explain the inp.txt, it would have been helpfull if you actually did.
        Is that file realy nessesary??? Or,
        Does the executable.exe edit the file?
        How does the last line in inp.txt look like?


        \Rems
        Last edited by Rems; 28th June 2010, 13:13.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X