Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Batch FOR Loop %ERRORLEVEL%
Name: jboswell Date: October 28, 2005 at 12:56:10 Pacific 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.
Summary: I have written a lengthy script for work to remotely install services, remotely kill processes, etc. and am stuck on one thing. On an individual basis, it works like a charm. Now I'm wanting to sta...
Summary: To Mechanix2Go, when calling a 'function' ..i.e. call :sub1 %%a the function uses the space as a delim instead of keeping the same delim as the for loop. How do I make it treat the parameters (%1,%2,...
Summary: I have a FOR loop in a Batch Script on XP Pro. FOR /L %%A IN (1 1 %engine_instance%) DO ( type %logs_dir%\sim_engine_%%A.log | FIND "Customers Processed This Run" > %logs_dir%\run_sim_temp_%%A.txt ...