How to store %Errorlevel% to variable for later use?
Posted: 25 Jan 2019 04:50
I need to extend a script by the ability to check the output of a text dump. The script has to know the existence of a specific pattern and should store its state to a variable (0 or 1, basically). The text dump will be some formatted xml output and the pattern looks like <!-- foo:1 --> followed by a linefeed.
I tried the following which doesn't work:
If %Errorlevel%==0 won't work either. The type foo.log will be replaced by a curl command later on.
Instead of the Echo lines I'd like to have some kind of Set ReturnValue=%Errorlevel% instruction as soon as that part works.
If I manually execute the commandor apply it to a text dump sans pattern:
I'll correctly get as Echo %Errorlevel% the results 0 and 1.
I wonder where the (logical?) error is...
I tried the following which doesn't work:
Code: Select all
type foo.log | findstr /r /c:"\<!-- foo:1 --\>" >nul
If %Errorlevel% Equ 0 (
Echo %Errorlevel%
) Else (
Echo %Errorlevel%
)
Instead of the Echo lines I'd like to have some kind of Set ReturnValue=%Errorlevel% instruction as soon as that part works.
If I manually execute the command
Code: Select all
type foo.log | findstr /r /c:"\<!-- foo:1 --\>" >nul
Code: Select all
type bar.log | findstr /r /c:"\<!-- foo:1 --\>" >nul
I wonder where the (logical?) error is...