在将输出重定向到批处理文件中的文件时异步执行命令? [英] Execute a command asynchronously while redirecting the output to a file in a batch file?

查看:243
本文介绍了在将输出重定向到批处理文件中的文件时异步执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在批处理文件中,我要异步执行 myCommand (无需等待它完成)。我不想在新的控制台窗口中执行 myCommand

Let's say in a batch file, I want to execute myCommand asynchronously (without waiting for it to finish). And I don't want to execute myCommand in a new console window.

同时,我要重定向 em> myCommand to output.txt

At the same time, I want to redirect the output of myCommand to output.txt

所以在批处理文件中,如果我写

So in the batch file, if I write

START myCommand > output.txt

output.txt将为空,我会看到一个新窗口。

output.txt will be empty and I will see a new window.

如果我写

myCommand > output.txt

那么我无法异步执行。

有没有办法,我可以实现所有这三个要求? (异步,没有新窗口,重定向输出)

Is there any way I can achieve all these three requirements? (asynchronously, no new window, redirect output)

谢谢!

推荐答案

p>我没有完全测试,但我认为这可能工作:

I haven't tested it fully, but I think this may work:

start /b "" myCommand >output.txt

我相信这两种形式都很好 - 唯一的区别是如果标准错误被重定向,START无法启动myCommand。

I believe both forms work fine - the only difference is if standard error is redirected as well and START fails to launch myCommand.

重定向START:将myCommand和START输出重定向到该文件。

Redirecting START: both myCommand and START output are redirected to the file.

start /b "" myCommand >output.txt >2&1

仅重定向myCommand:仅重定向myCommand输出。任何START错误信息将出现在屏幕上。请注意,我选择避免重定向,而不是使用引号如jeb

Redirecting myCommand only: Only myCommand output is redirected. Any START error message will appear on the screen. Note, I opted to escape the redirection instead of using quotes like jeb.

start /b "" myCommand ^>output.txt ^>2^&1

这篇关于在将输出重定向到批处理文件中的文件时异步执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆