简体   繁体   English

如何修复控制台窗口关闭的输出警告?

[英]How to fix output warning for console window close?

I'm running an *.exe file using a batch file and outputting its result in a file. 我正在使用批处理文件运行*.exe文件,并将其结果输出到文件中。 The batch file has the following commands: 批处理文件具有以下命令:

"..\..\GeneralData\exe\executable.exe" > B:\Simulations\7642\Time_20130101_20130111\output.txt
exit

I'm scanning output.txt to find when the task was successfully completed. 我正在扫描output.txt以查找任务成功完成的时间。 This works well when the application runs with no error because a "Successful finish" string is outputted. 当应用程序无错误运行时,这会很好地工作,因为会输出“成功完成”字符串。 The problem is when an error occurs as errors in this application can have multiple codes thus scan for every single option is virtually impossible. 问题是当错误发生时,此应用程序中的错误可能具有多个代码,因此几乎不可能扫描每个选项。

My idea was to output a message when the console window is closed (the exit command executed) and scan the output.txt trying to find the "Successful finish" string. 我的想法是在关闭控制台窗口(执行退出命令)时输出一条消息,并扫描output.txt尝试查找“成功完成”字符串。 If it is not present, it is an error. 如果不存在,则为错误。 I was trying to do the following: 我正在尝试执行以下操作:

start /MIN cmd /c "Model.bat || call echo %^errorLevel% > exitcode.txt"

But it doesn't output the exitcode.txt . 但是它不会输出exitcode.txt Can someone please give me some clue on how to do this? 有人可以给我一些如何做的线索吗?

In windows console errors are usually outputted to STDERR which could be redirected to a file in following manner: 在Windows控制台中,错误通常会输出到STDERR,可以通过以下方式将其重定向到文件:

executable.exe > output.txt 2> error.txt

In case your "executable.exe" provide exitcodes, you could catch it by %errorlevel% value IN THE NEXT LINE of code: 如果您的“ executable.exe”提供了退出代码,则可以在下一行代码中按%errorlevel%值捕获它:

executable.exe > output.txt 2> error.txt
if errorlevel 1 process_error.txt_routine

Notice that "if errorlevel" clause means, the errorlevel is EQUAL OR HIGHER than given number, so "if errorlevel 0" will be always true. 请注意,“ if errorlevel”子句的意思是,错误级别等于或大于给定的数字,因此“ if errorlevel 0”将始终为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM