How do I get the error level of commands in a pipe in Windows batch programming?

前端 未结 6 970
天涯浪人
天涯浪人 2021-01-03 18:22

Batch files return the error code of the last command by default.

Is it somehow possible to return the error code of a former command. Most notably, is it possible t

6条回答
  •  感动是毒
    2021-01-03 19:01

    To call tee for entry bat-file, not for single command, and use errorlevel freely, I use trick like this:

    if "%1" == "body" goto :body
    call %0 body | tee log.txt
    goto :eof
    :body
    
    set nls_lang=american_america
    set HomePath=%~dp0
    
    sqlplus "usr/pwd@tnsname" "@%HomePath%script.sql" 
    if errorlevel 1 goto dberror
    
    rem Here I can do something which is dependent on correct finish of script.sql    
    
    :dberror
    
    echo script.sqlerror failed
    

    it separates using tee from calling any commands inside batch.

提交回复
热议问题