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

Home Forums Scripting DOS Command Shell Batch file to edit a txt file that is part of a compiled exe file using for /f

This topic contains 3 replies, has 4 voices, and was last updated by Blood Blood 9 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    Sargeo80
    Member
    #149657

    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
    Avatar
    Silver23
    Member
    #292271

    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 ?

    Blood
    Blood
    Moderator
    #335697

    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?

    Rems
    Rems
    Moderator
    #227757

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

    Here you go

    @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 [COLOR=”Navy”][B]executable.exe[/B][/COLOR]
    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
    [/CODE]
    You didn’t explain the [B]inp.txt[/B], 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[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
    [/CODE]
    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

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.