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

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

问题描述

让我们在一个批处理文件中说,我想执行的 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.

与此同时,我要重定向输出的 myCommand 的到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

然后我无法异步执行它。

then I cannot execute it asynchronously.

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

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

谢谢!

推荐答案

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

I haven't tested 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 stderr 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输出重定向。任何启动的错误信息会出现在屏幕上。请注意,我选择逃避重定向而不是使用引号像杰布的。

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天全站免登陆