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... :)
Thanks for your answer... Unfortunately this does not work as well... :( See what I tried:
test1.bat:
echo off
set VAR1=" "
echo VAR1 before test2: %VAR1%
call test2.bat 2>&1 | tee log.txt
echo VAR1 after test2: %VAR1%
test2:
@echo off
set VAR1=ERROR
echo VAR1 in test2: %VAR1%
exit /B 1
Output when calling test1.bat:
VAR1 before test2: " "
VAR1 in test2: ERROR
VAR1 after test2: " "
As an other solution I tried to save "ERRORVALUE: 1" into the logfile in case there is an error. In the mainscript I wanted to parse the log looking for this string. Unfortunately saving the find-result to an environment variable does not work as well, I did as follows:
FOR /F "tokens=1 delims=" %%A in ('type %logDir%\03_applySqls.log | find /c "ERRORVALUE: 1"') do SET val=%%A
Error I get:
"|" ist syntaktisch an dieser Stelle nicht verarbeitbar.
So how can I at least parse my logfile and in case the string is found in the log I can return the value as an errorlevel?