rysic Posted October 13, 2010 Share Posted October 13, 2010 I want to write some check for Nagios to check tracert from one server to another (to check if connection is working via backup). My AutoIt stript looks like that: #include <Constants.au3> $troute = Run("cmd.exe /c tracert -d -h 1 10.50.10.125", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Sleep(200) ;MsgBox(0,"tracert",$troute) $tracert = StdoutRead($troute) ;MsgBox(0,"tracert",$tracert) $rezultat = StringRegExp ( $tracert, '10\.5[12]\.1?..\.253', 0) ;MsgBox(0,"tracert",$rezultat) If $rezultat = 1 Then ConsoleWrite("network communication is working via primary router") Exit(0) Else ConsoleWrite("network communication is working via backup router") Exit(2) EndIf but in my opinion it is not perfect because of Sleep(200)... so I try to use RunWait #include <Constants.au3> $troute = RunWait("cmd.exe /c tracert -d -h 1 10.50.10.125", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;Sleep(200) ;MsgBox(0,"tracert",$troute) $tracert = StdoutRead($troute) MsgBox(0,"tracert",$tracert) $rezultat = StringRegExp ( $tracert, '10\.5[12]\.1?..\.253', 0) ;MsgBox(0,"tracert",$rezultat) If $rezultat = 1 Then ConsoleWrite("network communication is working via primary router") Exit(0) Else ConsoleWrite("network communication is working via backup router") Exit(2) EndIf but with RunWait, $tracert variable is empty... Can someone tell me why? THX and sorry for my english Link to comment Share on other sites More sharing options...
whim Posted October 13, 2010 Share Posted October 13, 2010 (edited) From the helpfile: Run("program") returns the PID, but RunWait("program") returns the program's exit code ... HTH, whim edit: ...and welcome to the forum ! edit2: typo's Edited October 13, 2010 by whim Link to comment Share on other sites More sharing options...
wakillon Posted October 13, 2010 Share Posted October 13, 2010 (edited) Welcolme to the forum and try like this ! #include <Constants.au3> $troute = Run("cmd.exe /c tracert -d -h 1 10.50.10.125", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While ProcessExists ( $troute ) $_StderrRead = StderrRead ( $troute ) If Not @error And $_StderrRead <> '' Then ConsoleWrite ( "STDERR read : " & $_StderrRead & @Crlf ) EndIf $_StdoutRead = StdoutRead ( $troute ) If Not @error And $_StdoutRead <> '' Then ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @Crlf ) EndIf Wend Edited October 13, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
rysic Posted October 13, 2010 Author Share Posted October 13, 2010 (edited) I think, that it is good idea because with RunWait I must use some tmp file (Am I right?). Now it looks like that: #include <Constants.au3> $troute = Run("cmd.exe /c tracert -d -h 1 10.50.10.125", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;Sleep(200) $tracert="" While ProcessExists ( $troute ) $_StderrRead = StderrRead ( $troute ) If Not @error And $_StderrRead <> '' Then ConsoleWrite ( "STDERR read : " & $_StderrRead & @Crlf ) EndIf $_StdoutRead = StdoutRead ( $troute ) If Not @error And $_StdoutRead <> '' Then $rezultat = StringRegExp ( $_StdoutRead, '10\.5[12]\.1?..\.253', 0) If $rezultat = 1 Then ;MsgBox(0,"tracert",$_StdoutRead) ConsoleWrite("network communication is working via primary router") Exit(0) EndIf EndIf Wend ConsoleWrite("network communication is working via backup router") Exit(2) And works very well. Thanks! Edited October 13, 2010 by rysic Link to comment Share on other sites More sharing options...
wakillon Posted October 13, 2010 Share Posted October 13, 2010 I think, that it is good idea because with RunWait I must use some tmp file (Am I right?).Now it looks like that:And works very well. Thanks!Glad to help you but read helpfile for StdoutRead ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
rysic Posted October 13, 2010 Author Share Posted October 13, 2010 Glad to help you but read helpfile for StdoutRead ! I red that: http://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm and i don't see any problem... but I'm not programmer Link to comment Share on other sites More sharing options...
wakillon Posted October 13, 2010 Share Posted October 13, 2010 I red that: http://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm and i don't see any problem... but I'm not programmer I didn't say there was a problem, but if you wanted more precisions, then see this function in helpfile ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
rysic Posted October 13, 2010 Author Share Posted October 13, 2010 (edited) What do you meen by helpfile? AutoIt3Help.exe in AutoIt directory??? If yes, in that file is the same page as here: http://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm Ad. edit: WELCOME! Ad. edit2: What "typo's" means? Edited October 13, 2010 by rysic Link to comment Share on other sites More sharing options...
GEOSoft Posted October 13, 2010 Share Posted October 13, 2010 (edited) typos = typographical errors, usually Spelling mistakes. Edited October 13, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
rysic Posted October 13, 2010 Author Share Posted October 13, 2010 typos = typographical errors, usually Spelling mistakes.Well... I still learn English Link to comment Share on other sites More sharing options...
GEOSoft Posted October 13, 2010 Share Posted October 13, 2010 (edited) Nobody was faulting you for anything and believe me when I say that we see a lot of people here whose native language is not English. The ones that annoy me are the ones who have English as their native tongue and still insist on typing jibberish or won't take the time to check what they have typed. We all do that at times and in whims case he checked it a bit too late so he came back and edited the post to make the corrections hence the use of "Edit typo". He was just explaining why the post showed as having been edited. Edited October 14, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
rysic Posted October 13, 2010 Author Share Posted October 13, 2010 Nobody was faulting you for anything and believe me when I say that we see a lot of people here whose native language is not English. The ones that anoy me are the ones who have English as their native tongue and still insist on typing jibberish or won't take the time to check what they have typed. We all do that at times and in whims case he checked it a bit too late so he came back and edited the post to make the corrections hence the use of "Edit typo". He was just explaining why the post showed as having been edited.OK! I understand it now! In Poland we have also so many people who don't care about mistakes in native language... but we have so many ambitious moderators too Well... enough that off topic 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