1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Exit code of a batch file?

Discussion in 'Support' started by vefatica, Jan 26, 2016.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    This is from the LE forum but it is equally appropriate here.

    Here are two simple batch files.
    Code:
    v:\> type chain1.cmd
    @echo off
    if "%1"=="1" (cmd /c exit 1) else (echo foo)
    
    v:\> type chain2.cmd
    @echo off
    echo chain2.cmd was executed
    Here's the result of conditional execution with CMD.
    Code:
    V:\> chain1.cmd 1 && chain2.cmd
    
    V:\>
    And here's the result with TCC19.
    Code:
    v:\> chain1.cmd 1 && chain2.cmd
    chain2.cmd was executed
    
    v:\>
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    This appears to be an obvious CMD bug -- are you saying you want TCC to emulate it?
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    What's the bug? Under CMD. chain1.cmd returns 1 (the result of "cmd /c exit 1") and chain2.cmd isn't executed.
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    Replace "cmd /c exit 1" with any external that fails. Here's another using "net stop stisvc".

    CMD doesn't run the second batch file (seems right).
    Code:
    V:\> chain1.cmd 1 && chain2.cmd
    The Windows Image Acquisition (WIA) service is not started.
    
    More help is available by typing NET HELPMSG 3521.
    
    V:\>
    And TCC does run the second batch file.
    Code:
    v:\> chain1.cmd 1 && chain2.cmd
    The Windows Image Acquisition (WIA) service is not started.
    
    More help is available by typing NET HELPMSG 3521.
    
    chain2.cmd was executed
    
    v:\>
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    ... or an internal that fails. "DIR *.noexist" does the same thing. CMD thinks the batch file failed and TCC thinks it succeeded.
     

Share This Page