简体   繁体   中英

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. 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. 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. 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 . 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:

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 > 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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