Windows batch file: Pipe destroys my return code

Posted by murxx on Stack Overflow See other posts from Stack Overflow or by murxx
Published on 2010-05-18T13:14:40Z Indexed on 2010/05/18 15:00 UTC
Read the original article Hit count: 179

Filed under:
|
|

Hi,

is it possible to return the errorlevel also if I pipe the output of a script into a logfile:

test1.bat:

 call test2.bat 2>&1 | tee log.txt
 echo ERRORLEVEL: %ERRORLEVEL%

test2.bat:

 exit /B 1

Output when calling test1.bat:

 ERRORLEVEL: 0

The errorlevel is always 0.

The problem is, I want to call another script inside my script where the output should be redirected synchronously with the output shown in the command line, therefore a simple > is not enough for me. I tried several ideas, but result is that the pipe always seems to destroy the given error-level... :(

Can you give me any further suggestions?

Thanks in advance... :)

© Stack Overflow or respective owner

Related posts about cmd

Related posts about batch