My MS-DOS batch file doesn't work

March 30, 2009 at 07:42:46
Specs: Windows XP
I never write script before. Still learning...
I wrote a script as the following:

IF "%%I"=="Request timed out" in ('ping 192.168.1.110') (
echo timedout>timedout.txt
) ELSE (
echo OK>ok.txt
)

My intention is to check if the ping from the IP address give "Request timed out", it will do COMMAND A else it would do COMMAND B.

but it just didn't work. It echo both files. It should be ONLY one output. Can anyone debug this?


See More: My MS-DOS batch file doesnt work

Report •


#1
March 30, 2009 at 09:31:43
There is no ELSE in DOS.

======================
@echo off

ping 192.168.1.110 | find "Request timed out" > nul

goto :%errorlevel%
:
echo OK>ok.txt
goto :eof
:0
echo timedout>timedout.txt
:eof


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
March 30, 2009 at 09:41:15
Thank you.
It is half-worked. it successfully echo the last timedout.txt if the IP is not active/disconnected but when the IP is active/connected it do not echo the ok.txt...nothing appears. why?

Report •

#3
March 30, 2009 at 09:53:47
oops... I goofed up.

=========================
@echo off

ping 192.168.1.110 | find "Request timed out" > nul

goto :%errorlevel%
:1
echo OK>ok.txt
goto :eof
:0
echo timedout>timedout.txt
:eof


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
March 30, 2009 at 10:01:59
Now it works perfectly! Thank you very2 much!
The only remaining thing is now I am enticed to learn all the commands that you use...any good references from the internet?

Report •

#5
March 30, 2009 at 10:38:37
Try this book:

http://www.amazon.com/gp/offer-list...


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question