Running an .exe file through a batch file and passing parameters

15,530

Solution 1

try this, it works with AVI as the main extension, you may change this:

@echo off &setlocal enabledelayedexpansion
for %%i in (*.avi) do (
    set "line="
    for %%j in ("%%~ni.*") do set line=!line! -"%%~j"
    start "" test_app.exe !line!
)

Solution 2

Try this with your avi files. It will just echo the bunch of commands and you can see what it does. The - signs seem a bit odd but I included them with the names.

@echo off
for %%a in (*.avi) do (
echo exe.file "-%%a" "-%%~na.txt"
)
pause
Share:
15,530
MaxPower
Author by

MaxPower

Always learning...

Updated on June 16, 2022

Comments

  • MaxPower
    MaxPower almost 2 years

    I have an .exe file that takes two parameters when i run it from the command line, as such:

    test_app.exe -vid.avi -data.txt
    

    How would i be able to START the .exe file through a batch script and pass it those parameters?

    If i have multiple .avi and .txt files that i need to pass to the .exe file through START, how would i be able to have a variable that goes through all of those files two at a time? (pairing every .avi with it's correspondant .txt).

    Let's assume that every pair of .avi and .txt share the same name but obviously have different extensions.

    I need to write something like this:

    @ECHO OFF
    START test_app.exe -vid.avi -data.txt
    pause
    

    But the parameters should be variables that increment every time a pair of parameters are proccessed through the .exe so it would loop on all of the files in the CWD.

    Trying to do this but seems like START does not work that way?

    @echo off
    for %%a in (*.avi) do (
    START Tester.exe -%%a -%%~na.txt
    )
    pause
    
  • MaxPower
    MaxPower almost 11 years
    Is the .txt file also added into !line!? It's a bit confusing for me since i barely have any experience with this, sorry.
  • Endoro
    Endoro almost 11 years
    All files with the same name are on the line, eg. vid.avi, vid.txt, vid.dta. What files do you need at one line?
  • MaxPower
    MaxPower almost 11 years
    in every line i need to start the exe and give it two parameters... the avi and txt files.
  • MaxPower
    MaxPower almost 11 years
    I need to actually start the exe file with those parameters, i don't understand how echo helps here... sorry if i totally missed the point.
  • foxidrive
    foxidrive almost 11 years
    You haven't supplied an authentic command line - but I supplied the code to launch the exe with the two files. All you need to do is replace the exe filename, and remove the echo, assuming that "-filename.avi" "-filename.txt" is what you need to feed the exe file with. The echo was to show you what the code was doing.
  • foxidrive
    foxidrive almost 11 years
    Your command line looks wrong. The switches aren't normal. MOITester.exe doesn't get a hit in google so I can't help you with what the syntax is.
  • MaxPower
    MaxPower almost 11 years
    MOITester is just a random name. I don't understand what you mean by the switches aren't normal. all i'm trying to do is call tester.exe and pass it two arguments at a time. One being .avi and the other being .txt
  • foxidrive
    foxidrive almost 11 years
    test_app.exe -vid.avi -data.txt Does that work for you? It is the information you provided, and if it doesn't work then the code I provided isn't going to work either. Show us what works for you with your executable.
  • Endoro
    Endoro almost 11 years
    And where do the parameters come from?
  • MaxPower
    MaxPower almost 11 years
    from the current directory. It has a bunch of avi's and txt's. every pair of avi+txt share the same name
  • Endoro
    Endoro almost 11 years
    @MaxPower yes, this does my code: search for an AVI and collect all files with the same name & put it at the line.
  • MaxPower
    MaxPower almost 11 years
    this "test_app.exe -vid.avi -data.txt" works through the command line. But through a batch file i need to use START i think... and that is what does not work. I can only do it one by one using hte command line. What i am trying to do is automate the proccess to have it run on all files in the current directory.