有任何方式重定向stderr输出从命令运行与“开始”在Windows命令行中? [英] Is there any way to redirect stderr output from a command run with "start" in the Windows command line?

查看:704
本文介绍了有任何方式重定向stderr输出从命令运行与“开始”在Windows命令行中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我想要自动运行,因为它需要一段时间才能完成。由于某种原因,它将所有内容输出到stderr而不是stdout,我想检查其进度,所以我发现自己需要在start命令中重定向stderr输出。



我试过:

 开始My_ProgramC:\Users\Me\my_program.exe -some --presets --for 
--my_program.exe --outputC:\Users\Me\output_file_for_my_program
C:\Users\Me\input_file_for_my_program 2"C:\Users\Me\my_program_output.log

重定向是由开始,所以我得到一个0字节文件的结果 start - 即,没有。有什么办法使输出重定向以某种方式附加到my_program的输出?



我已经尝试了转义,并且 ^ 2> 2 ^> 似乎工作。



<$ p

解决方案

$ p> 开始My_Program%SystemRoot%\System32\cmd.exe/ cC:\Users\Me\my_program.exe--some --presets --for --my_program.exe --outputC:\Users\Me\output_file_for_my_programC:\Users\Me\input_file_for_my_program2>C:\Users\Me\ my_program_output.log

显然,这里没有我的程序本身。如果我们认为内置的FIND.EXE命令返回STDERR上的文件未找到 - 文件名,以下是为我工作:

  startMy_Program%SystemRoot%\System32\cmd.exe/ cfind / v / iblargc:\\\
ot a real file.txt2& \stderr.txt


I have a program that I want to automate runs for, since it takes awhile to complete. For some reason it outputs everything to stderr instead of stdout, and I'd like to check on its progress, so I find myself needing to redirect stderr output within a start command.

I tried this:

start "My_Program" "C:\Users\Me\my_program.exe" --some --presets --for 
--my_program.exe --output "C:\Users\Me\output_file_for_my_program" 
"C:\Users\Me\input_file_for_my_program" 2>"C:\Users\Me\my_program_output.log"

But it turns out that the redirect is being picked up by start, so that I get a 0-byte file with the result of start - namely, nothing. Is there any way to make the output redirection attach in some way to the output of my_program?

I've experimented with escaping, and neither ^2> nor 2^> seem to work. Any help would be greatly appreciated!

解决方案

Try this:

start "My_Program" "%SystemRoot%\System32\cmd.exe" /c ""C:\Users\Me\my_program.exe" --some --presets --for --my_program.exe --output "C:\Users\Me\output_file_for_my_program" "C:\Users\Me\input_file_for_my_program" 2>"C:\Users\Me\my_program_output.log""

Obviously, not having "My Program" here I can't test this, per se. If we take that the built-in "FIND.EXE" command returns "File not found - filename" on STDERR, the following is working for me:

start "My_Program" "%SystemRoot%\System32\cmd.exe" /c "find /v /i "blarg" "c:\not a real file.txt" 2> C:\stderr.txt"

这篇关于有任何方式重定向stderr输出从命令运行与“开始”在Windows命令行中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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