problem with batch file running in windows 7 pro workstation

trying to echo %%1 to success.txt, if it fails, I want to send it to fail.txt (Nothing outputs to success.txt or fails.txt. What am i doing wrong ?
Windows 7 pro in a win2k8 domain

test.bat
cls
for /f %%i in (wks2.txt) do ping %%i -n 1 | find "Reply">nul
if not errorlevel 1 echo %%i>success.txt
HelpMe01Asked:
Who is Participating?
 
HackooConnect With a Mentor Commented:
You can take a look at this : Pinging Multiple PCs and Adding Text
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
What do you want to do?  Ping a list of workstations and generate a list of those that respond?  If so, your batch file is highly flawed.  The last error state is the one that's echoed (or would be if that part were right) which means you could have station1 to station5 and if 1-4 are on but 5 is off, you just get nothing.  Plus, you're overwriting success.txt every time you run the batch file.

Try this:

@echo off
Set OutputFile=success.txt
If Exist %OutputFile% Del %OutputFile%
for /f %%a in (list.txt) do (
	ping -n 1 %%a | find /i "reply">nul
	if "%errorlevel%" NEQ "1" echo %%a>>%OutputFile%
)

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I don't see the "falling" part:
cls
del success.txt fail.txt 2>nul
for /f %%i in (wks2.txt) do ping %%i -n 1 | find "Reply">nul && echo %%1>>success.txt || echo %%i>>fail.txt
if not errorlevel 1 echo %%i>success.txt

Open in new window

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Shaun VermaakTechnical Specialist/DeveloperCommented:
If you can add a utility to the target computer, use ifping
http://www.anykeyonline.nl/oldsite/documents/44.html
0
 
HelpMe01Author Commented:
Solution by Lee W - the output has all workstations whether they work or not in success.txt (Doesn't work)
Solution by Hackoo - Is there anyway to separate the output into two files. worked.txt and failed.txt (worked, but I need a few changes)
Solution by Shaun Vermaak - Boss won't let me use third party apps
0
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
The last line im my code suggestion is a left-over of my edit, it needs to be removed. And the code contains a typo. Correct lines are:
cls
del success.txt fail.txt 2>nul
for /f %%i in (wks2.txt) do ping %%i -n 1 | find "Reply">nul && echo %%i>>success.txt || echo %%i>>fail.txt

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.