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 arg3While the programs run as expected, all output is shown on stdout.
44 Answers
You might need to do it this way:
start cmd /c python 1st.py arg1 arg2 ^> out.txt 5 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
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.)
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.txtthe_second.bat then looks like this:
python 1st.py %1 %2 > %3 5