Name: jboswell Date: October 28, 2005 at 12:56:10 Pacific Subject: Batch FOR Loop %ERRORLEVEL% OS: Windows XP CPU/Ram: Lots
Comment:
Here is the code:
for /f %%Q in (machines.txt) do ( ping -n 1 -w 3 %PingThis% IF %ERRORLEVEL% == 0 echo %%Q >> alive.txt ELSE echo %%Q Failed Ping >> dead.txt )
Now, the problem is this. In machines.txt is 3 names:
koala joe solitude
"joe" is not an actual computer, so when the second loop goes to ping "joe" it will fail. Normally on the command line, when a ping fails, it sets %ERRORLEVEL% to 1. In a batch file WITHOUT a FOR loop, it will work but when I try to query %ERRORLEVEL% and sort which machines I can ping and which I can't, and I am trying to see if "joe" failed, I can't. When "joe" gets pinged and FAILS, it doesn't return a success/failure code to %ERRORLEVEL% at all.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE