Get Exitcodes from WindowsForms Application in command window

北城余情 提交于 2019-12-01 00:39:27
Fowl

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!