开发者

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜