windows 是否可以使用 start 来使用来自 cmd 文件的输出重定向?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3401877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to use output redirections from a cmd file using start?
提问by Fran?ois
I want to have a cmd file with something like:
我想要一个类似于以下内容的 cmd 文件:
:one
start /wait (blabla1.exe -q -m 1>blabla1.log 2>&1)
:two
start /wait (blabla2.exe -q -m 1>blabla2.log 2>&1)
where I want the output of the blabla application not the output of the start command.
我想要 blabla 应用程序的输出而不是 start 命令的输出。
Is it even possible to have the redirections "local" inside the start command?
甚至可以在 start 命令中使用“本地”重定向吗?
Do I have to create a 1 line cmd containingblabla1.exe -q -m 1>blabla1.log 2>&1
and pass it to the start
command?
我是否必须创建一个包含 1 行 cmdblabla1.exe -q -m 1>blabla1.log 2>&1
并将其传递给start
命令的行?
Update: I need the first one (blabla1.exe) to be finished before I launch the 2nd one (blabla2.exe). That's the reason for using start /wait
.
更新:在启动第二个 (blabla2.exe) 之前,我需要完成第一个 (blabla1.exe)。这就是使用start /wait
.
(Windows XP and up)
(Windows XP 及更高版本)
采纳答案by Joshua McKinnon
Given that you are redirecting output to a file, and waiting for the process to finish, is the extra window started by 'start' actually required? In fact, if there WAS some way to redirect the output when using start, then the windows that popped up wouldn't even have any output...making them even more meaningless.
鉴于您正在将输出重定向到一个文件,并等待该过程完成,实际上是否需要由 'start' 启动的额外窗口?事实上,如果在使用 start 时有某种方法可以重定向输出,那么弹出的窗口甚至不会有任何输出......使它们变得更加无意义。
If not, simply remove the "start /wait" and call the exes directly.
如果没有,只需删除“开始/等待”并直接调用exes。
If it IS necessary...then I'm not sure.
如果有必要……那我不确定。
UPDATE: I am fairly certain just removing the "start /wait" will produce the behavior you desire. See below:
更新:我相当肯定只是删除“开始/等待”会产生你想要的行为。见下文:
(Create the following batch file: foo.cmd
(创建以下批处理文件:foo.cmd
:one
notepad.exe
:two
dir
Note that dir will not echo until you close notepad.
请注意,在您关闭记事本之前,dir 不会回显。
回答by Benjamin McGill
Yes it is possible to redirect output using start wait command using the /B switch.
是的,可以使用 /B 开关使用 start wait 命令重定向输出。
start /B /wait myprog.exe >> output.log
If you need to break in you will have to use Ctrl+Break, Ctrl+Cwill be ignored. Hope this helps.
如果您需要闯入,则必须使用Ctrl+ Break,Ctrl+C将被忽略。希望这可以帮助。