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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
HackooCommented:
You can take a look at this : Pinging Multiple PCs and Adding Text
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", 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
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

Shaun VermaakTechnical Specialist IVCommented:
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
Qlemo"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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.