Guest ghetek Posted June 18, 2004 Share Posted June 18, 2004 I want to report the errorlevel from a dos ping to autoit. is there a way to do that? Link to comment Share on other sites More sharing options...
tutor2000 Posted June 18, 2004 Share Posted June 18, 2004 I want to report the errorlevel from a dos ping to autoit. is there a way to do that?I've seen it scripted in the autoit forum with yahoodo a >ping.txt to get the ping content then parse itRick Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm Link to comment Share on other sites More sharing options...
pekster Posted June 18, 2004 Share Posted June 18, 2004 (edited) Here's an example of using the return of a DOS command. This method only works with RunWait (and not Run) but it will return the exit code of the program that was run. In the case of ping, a 0 means the host was up and 1 means it was down.$result = RunWait(@ComSpec & " /c ping www.google.com", "", @SW_HIDE) MsgBox(0, "Trial 1", "Result of google ping: " & $result) $result = RunWait(@ComSpec & " /c ping www.goble-de-gook.com", "", @SW_HIDE) MsgBox(0, "Trial 2", "Result of garbage ping: " & $result)Edited to make more sense Edited June 18, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
midiaxe Posted June 18, 2004 Share Posted June 18, 2004 (edited) Try the following code. It displays the errorlevel from ping command: $sCmd = @ComSpec & " /c ping.exe" ; displays "0" $sCmdParm = "www.yahoo.com" $iRetCode = RunWait( $sCmd & " " & $sCmdParm) MsgBox( 0, "Ping Return Code", $iRetCode ) ; displays "1" $sCmdParm = "test.yahoo.com" $iRetCode = RunWait( $sCmd & " " & $sCmdParm) MsgBox( 0, "Ping Return Code", $iRetCode ) Edited June 19, 2004 by midiaxe Link to comment Share on other sites More sharing options...
Doxie Posted July 1, 2004 Share Posted July 1, 2004 aaaaaaaaaaaaaah :postal: I need help, this is driving me crazy When i ping a "unknown host" your script works fine (it send back result 1), but if i ping a server that is not responding, it still give me a 0 as its working. Would it be possible to: Ping a server: Result = 1 (unknow host) write to ini "fail" Look for the word "Request timed out" and write to ini "fail" Result = 0 (Reply) write to ini "Succed" argh, why is it giving me a 0 if there is no reply Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Arctor Posted July 1, 2004 Share Posted July 1, 2004 ...When i ping a "unknown host" your script works fine (it send back result 1), but if i ping a server that is not responding, it still give me a 0 as its working....argh, why is it giving me a 0 if there is no reply Because the server was reached and the ping did it's job successful.When the server is not answering to the ping, it's not the fault of ping.exeI don't have a server here wich is configured not to answer to a ping, so that I could test it. But I think it must be some kind of that reason.arctor Link to comment Share on other sites More sharing options...
Doxie Posted July 1, 2004 Share Posted July 1, 2004 (edited) I found this in the other thread: var = FileRead ("mypath\my.txtr", FileGetSize ("mypath\my.txt )) if stringinstr ($var,"mystring") then msgbox(4096,"Hurray","Only one line of code and I don't have to read line by line") endif And think i will use that, if i can get the ping result into a txt file. And one know how i can pipe the result? ping.exe www.autoitscript.com > test.txt Will that work? yea, it works Sorry for posting before testing, but i'm getting used to get errors all the time Edited July 1, 2004 by Doxie Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
tutor2000 Posted July 1, 2004 Share Posted July 1, 2004 I found this in the other thread: var = FileRead ("mypath\my.txtr", FileGetSize ("mypath\my.txt )) if stringinstr ($var,"mystring") then msgbox(4096,"Hurray","Only one line of code and I don't have to read line by line") endif And think i will use that, if i can get the ping result into a txt file. And one know how i can pipe the result? ping.exe www.autoitscript.com > test.txt Will that work? yea, it works Sorry for posting before testing, but i'm getting used to get errors all the time hehe I just posted that you may need http: but ya that's what I've seen people do don't forget to clear the var when you're done $var="" Rick Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm Link to comment Share on other sites More sharing options...
Doxie Posted July 1, 2004 Share Posted July 1, 2004 Hurray!!! Its all working ping.exe -n 1 127.0.0.1 > test.txt ;This is making a reply ping.exe -n 1 192.168.0.1 > test.txt ;This is not making a reply $var = FileRead ("test.txt", FileGetSize ("test.txt" )) if stringinstr ($var,"Reply") then msgbox(4096,"Hurray","Reply") Else msgbox(4096,"Doh","No Reply") endif I need this line because i'm making a ADSL Status tool for my users. And this "function" is need to test if they are logged in to their ISP. If they can ping 10.0.0.6, they got contact with their ISP. If they can ping www.microsoft.com, they are logged in. If 10.0.0.6 succed, but microsoft fails, it will open their login page. It also check some other settings, and now it all works perfectly, this was the last problem i had. Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted July 1, 2004 Share Posted July 1, 2004 don't forget to clear the var when you're done$var=""RickEverytime i run the ping it rewrite the txt file, so i get a fresh txt file each time.What exactlly could happend if i dont clear the $var? Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Arctor Posted July 1, 2004 Share Posted July 1, 2004 (edited) ... ping.exe www.autoitscript.com > test.txt ...When you are already on the cmdline, why do not do the rest of it also there. You don't need to redirect to a textfile, then load it with autoit and then find the right string in autoit. Just use a one liner. Pipe the output to find. The /i makes it caseunsensitiv. $res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"') MsgBox(0, "Output", "PingResult: " & $res) When string is found you will get errorlevel 0, if not, errorlevel 1. You can also use a ping.exe -n 1 for just ping one time instead of three. One Note: To get back the errorlevel from a commandline-prog as a result in AutoIt don't seems to work with Win98. arctor Edit: Forgot a space. -n 1 @Tutor2000: You don't need HTTP for a ping Edited July 1, 2004 by Arctor Link to comment Share on other sites More sharing options...
Doxie Posted July 1, 2004 Share Posted July 1, 2004 Sweet dude... One less file to think about Even tough this is taking a bit longer (if no reply) then it does with > .txt Wonder why is that? But i prefer your last suggestion, very nice and handy. Thanks, ill mention your name in the "About" hehe Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
edy Posted July 1, 2004 Share Posted July 1, 2004 Sweet dude...One less file to think about Even tough this is taking a bit longer (if no reply) then it does with > .txtWonder why is that? But i prefer your last suggestion, very nice and handy.Thanks, ill mention your name in the "About" hehefor me it is better to find the string "TTL" , because ,for example, in Windows Xp Italian "Reply" is translated "risposta".bye Link to comment Share on other sites More sharing options...
tutor2000 Posted July 2, 2004 Share Posted July 2, 2004 When you are already on the cmdline, why do not do the rest of it also there. You don't need to redirect to a textfile, then load it with autoit and then find the right string in autoit. Just use a one liner. Pipe the output to find. The /i makes it caseunsensitiv. $res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"') MsgBox(0, "Output", "PingResult: " & $res) When string is found you will get errorlevel 0, if not, errorlevel 1. You can also use a ping.exe -n 1 for just ping one time instead of three. One Note: To get back the errorlevel from a commandline-prog as a result in AutoIt don't seems to work with Win98. arctor Edit: Forgot a space. -n 1 @Tutor2000: You don't need HTTP for a pingI don't like find I've found it worked differently with different OS's. Could be my inexptitude (and spelling ld) Thanks for the http info Rick Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm Link to comment Share on other sites More sharing options...
Doxie Posted July 2, 2004 Share Posted July 2, 2004 $res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"') Why does not @SW_HIDE work with above code? Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
SlimShady Posted July 2, 2004 Share Posted July 2, 2004 (edited) $res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"') Why does not @SW_HIDE work with above code?I had the same problem with the PowerArchiver commandline tool. (Using your command as an example) I used this: $res = RunWait(@ComSpec & ' /k ping www.yahoo.com | find /i "string_you_want_to_find && EXIT"', '', @SW_HIDE) Edited July 2, 2004 by SlimShady Link to comment Share on other sites More sharing options...
Developers Jos Posted July 2, 2004 Developers Share Posted July 2, 2004 Works for me, could it be you forgot the parameter for the startup Path before the @SW_HIDE ? Try this one: $res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"','',@SW_HIDE) msgbox(0,'debug',$res) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Doxie Posted July 2, 2004 Share Posted July 2, 2004 Thanks, is now working. Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now