Start /wait /b not exiting program when there is an error

前端 未结 1 1360
無奈伤痛
無奈伤痛 2020-12-21 09:00

I have a batch file that will run several other file (lets call it procedure file) such as .bat,.exe,.py, etc...

if Not Exist JobStreamUnitTest_CreateTextPyt         


        
相关标签:
1条回答
  • 2020-12-21 10:00

    I have found some issues in start /WAIT /B any_program || exit %errorlevel%:

    • #1 - %errorlevel% variable will be expanded at parse time. Thus your script never returns proper exit code. See EnableDelayedExpansion.
    • #2 - || conditional command execution: unfortunately I can't document it properly, but all my attempts with it failed in relation to start command...

    IMHO next code snippet (the only example) could work as expected:

    if Not Exist JobStreamUnitTest_CreateTextBatch_4-27-2015.txt (
        start /B /WAIT C:\Users\blee2\Documents\UnitTest\CreateNewFile.bat
        SETLOCAL enabledelayedexpansion
        if !errorlevel! NEQ 0 exit !errorlevel!
        ENDLOCAL
        copy /y nul JobStreamUnitTest_CreateTextBatch_4-27-2015.txt
    )
    
    • #3 - a bug in the implementation of the start command.

    start /WAIT /B doesn't work (the /wait argument is ignored):

    ==>start /WAIT /B wmic OS GET Caption & echo xxx
    xxx
    
    ==>Caption
    Microsoft Windows 8.1
    

    There's a simple workaround (from SupeUser) as start /B /WAIT works:

    ==>start /B /WAIT wmic OS GET Caption & echo xxx
    Caption
    Microsoft Windows 8.1
    
    xxx
    
    0 讨论(0)
提交回复
热议问题