具有重定向输出的批处理后台进程
我正在尝试从批处理文件运行多个后台进程并将输出定向到文件。在 Windows 中可以做到这一点吗?这是我尝试过的,但它最终引导启动程序的输出而不是后台进程。
start myapp.exe > myapp.out 2>&1
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,无需使用辅助批处理文件,这非常简单。您只需通过 cmd.exe 运行应用程序,并确保转义特殊字符,以便它们传递到 cmd.exe。
您可能不想看到额外的控制台窗口,因此请使用 START /B 选项。
每个已启动的进程必须将其输出定向到唯一的文件。多个进程不能共享同一个输出文件。
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.
Each STARTed process must have its output directed to a unique file. Multiple processes cannot share the same output file.
我认为您唯一的机会是为您想要启动的每个 exe 创建一个批处理文件。在批处理文件中,您可以重定向输出。然后,主批处理文件将“启动”批处理文件,而不是直接“启动”exe。
您只需要在每个批处理文件的末尾包含一个
exit
命令:start_myapp.cmd
包含以下内容:然后您可以运行
并且输出将被重定向
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:then you can run
and the output will be redirected