Link to home
Start Free TrialLog in
Avatar of HelpMe01
HelpMe01

asked on

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
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

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

ASKER CERTIFIED SOLUTION
Avatar of Hackoo
Hackoo
Flag of Tunisia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

If you can add a utility to the target computer, use ifping
http://www.anykeyonline.nl/oldsite/documents/44.html
Avatar of HelpMe01
HelpMe01

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial