Get Exitcodes from WindowsForms Application in command window

前端 未结 1 1501
慢半拍i
慢半拍i 2021-01-07 02:04

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

相关标签:
1条回答
  • 2021-01-07 02:37

    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.

    0 讨论(0)
提交回复
热议问题