Windows CMD Batch, START and output redirection
I would like to run two programs simultaneously from a batch file, and redirect the first program's output into a text file like:
start python 1st.py arg1 arg2 > out.txt
start 2nd.exe %1 arg2 arg3
While the programs run as expected, all output is shown on stdout.
Solution 1:
You might need to do it this way:
start cmd /c python 1st.py arg1 arg2 ^> out.txt
Solution 2:
Redirection is applied to the start
command, but somehow not to the cmd.exe
instance it runs.
If the >
operator is escaped, everything should work:
start 1st.py arg1 arg2 ^> out.txt
(If you want to redirect stderr as well, use 2^>
for it.)
Solution 3:
Additionally, if you want to redirect both stderr and stdout this works for me
start call delay.bat ^1^> log.txt ^2^>^&^1
It seems every character basically needs to be escaped. This command normally looks like this:
delay.bat 1> log.txt 2>&1
Solution 4:
What did the trick for me was moving the command into a separate batch file:
rem this first batch file triggers the second one:
start the_second.bat arg1 arg2 out.txt
the_second.bat then looks like this:
python 1st.py %1 %2 > %3