inconsistent ERRORLEVEL in a batch file
        Posted  
        
            by 
                Doron
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by Doron
        
        
        
        Published on 2012-03-27T09:35:29Z
        Indexed on 
            2012/03/28
            5:33 UTC
        
        
        Read the original article
        Hit count: 612
        
windows-7
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.)
© Server Fault or respective owner