darckeen
darckeen

Reputation: 960

Background processes in batch with redirected output

I'm trying to run several background processes from a batch file and have the output directed to a file. Is it possible to do this in Windows? This is what I've tried but it end up directing the output of the start program rather then background process.

start myapp.exe > myapp.out 2>&1

Upvotes: 9

Views: 7759

Answers (2)

dbenham
dbenham

Reputation: 130899

Actually it is quite easy without using a helper batch file. You just need to run the application via cmd.exe instead, and make sure to escape the special characters so they pass through to cmd.exe.

You probably don't want to see an extra console window, so use the START /B option.

start /b "" cmd /c myapp.exe ^>myapp.out 2^>^&1

Each STARTed process must have its output directed to a unique file. Multiple processes cannot share the same output file.

Upvotes: 12

user330315
user330315

Reputation:

I think the only chance you have is to create one batch file for each exe that you want to start. Inside the batch file you can redirect the output. The master batch file would then "start" the batch file, not the exe directly.

You just need to include an exit command at the end of each batch file:

start_myapp.cmd contains the following:

myapp.exe > myapp.out 2>&1
exit

then you can run

start start_myapp.cmd 

and the output will be redirected

Upvotes: 6

Related Questions