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

前端 未结 6 968
天涯浪人
天涯浪人 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:03

    One workaround is to make an indirection through a file.

    Like this

    foo.exe > tmp.txt
    set FOOERR=%ERRORLEVEL%
    cat tmp.txt
    exit %FOOERR%
    

提交回复
热议问题