I\'m starting a Windows Forms application from the command promt and I need to get the exit codes that the windows forms application generates. The command promt starts the
The answer is
start /wait [Your Command]
and then
echo %errorlevel%
to extract the return value.
--
And because I like writing batch files... (it's a problem of mine...)
@echo off echo Waiting for program to exit... start /wait %* echo Return code was %errorlevel%
Save it somewhere with a .bat extension. Run it with the command line of the program you want to run as it's arguments. It will run the command you gave it, wait for it to end, and then print the return value.
You could also hard code the program by replacing the start /wait line with your app, because as the docs (start /?) say:
When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script.
CMD will wait for a winform if it is called from a script whether or not Command Extensions are enabled.