inconsistent ERRORLEVEL in a batch file
- by Doron
In a batch file, I have an inconsistent errorlevel behavior:
The IP address 10.1.1.2 always replies.
The following code always gives errorlevel 0 in one location (somewhere in the middle - exactly where i need it) inside the batch file.
I copied only this snippet and placed it in the beginning and at the end of the batch file.
In those locations, the result is always 1.
Here is the code snippet:
ping 10.1.1.2|Findstr /I /C:"timed out" /C:"host unreachable"
echo %errorlevel%
Any idea how to make it work also in the middle of the file?
What am I doing wrong?
I would hate to solve it with GOTOs(to the end of the file and back to where I need the result.)