Windows Cmd Batch, Start and Output Redirection

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.

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

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

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.