M BUZZ CRAZE NEWS
// news

Windows CMD Batch, START and output redirection

By Sarah Rodriguez

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.

4

4 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.)

2

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
5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy