Let's say I have these commands:
Prog1.exe D:\SomeDir\Prog2.exe Prog3.exe
Now, say for the second line, I would like the working directory to be D:\SomeDir, but in Prog1.exe and Prog3.exe I want the default working directory (normally, where my .bat file is). If I try this
Prog1.exe cd D:\SomeDir D:\SomeDir\Prog2.exe Prog3.exe
Apparently Prog3 will be executed in SomeDir, which is not what I want.
Under Windows-10, go to All Apps, Windows System and the open the Command Prompt window. From the command prompt change directory to the batch file directory: cd \Tutorial\batch. Then type the name of the batch file test_conc followed by Enter.
If you want run command window from a specific folder. Click your folder then hold your shift key, then right click you will found option open command window here then click it.
Example# @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.
You could use the pushd/popd commands (help with pushd /?
)
Prog1.exe Pushd D:\SomeDir Prog2.exe popd Prog3.exe
You could use the cd command (help with cd /?
) with the %~dp0
, batch file path, variable.
Prog1.exe cd D:\SomeDir Prog2.exe cd %~dp0 Prog3.exe
For a complete list of %~
modifiers see call /?
or for /?
help.
However, I only add this as to provide a more complete answer on Stack Overflow. I would RECOMMEND using jeb's solution above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With