amakrkr Posted October 13, 2012 Posted October 13, 2012 Hello, could someone help me with my problem. What i am trying to do is check for an active connection to the server and here is the problem. How do i get a string or IP or anything back from CMD. So far i made this: Func ip_check() $IP = '192.168.1.1' $foo = 0; $foo = Run(@ComSpec & " /c " &'netstat -na | find "' & $IP & '"', '', @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) $line = StderrRead($foo) MsgBox(4096,"", "Connection is alive" , $line) EndFunc But i do not get anything. It would be enough if i would get $line = 0 if connection is dead and $line != 0 if alive. Please post if you have a solution! Thank you!
water Posted October 13, 2012 Posted October 13, 2012 Can you check that the process was successfully started? Means that $foo is not zero. It should be set to the ProcessId. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
amakrkr Posted October 13, 2012 Author Posted October 13, 2012 (edited) yea process is started. problem is that i am always getting something in value $foo. How can i get process name from proces id ... if process id is the number i am getting from that run command. Ps $line allways returns NULL value. What does that mean? Edited October 13, 2012 by amakrkr
kylomas Posted October 13, 2012 Posted October 13, 2012 amakrkr, Read ouput in a loop like this ; *** Start added by AutoIt3Wrapper *** #include <Constants.au3> ; *** End added by AutoIt3Wrapper *** #AutoIt3Wrapper_Add_Constants=n ip_check() Func ip_check() $IP = '192.168.1.1' $foo = 0; $foo = Run(@ComSpec & ' /c netstat -na', '', @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) while 1 $line = StdoutRead($foo) if @error then exitloop if stringlen($line) > 0 then consolewrite('+>> ' & $line & @lf) wend EndFunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
water Posted October 13, 2012 Posted October 13, 2012 Try this: Func ip_check() $IP = '192.168.1.1' $line = "" $foo = Run(@ComSpec & " /c " &'netstat -na | find "' & $IP & '"', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While ProcessExists($foo) $line &= StdOutRead($foo) WEnd MsgBox(4096,"", "Connection is alive" , $line) EndFunc My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
amakrkr Posted October 13, 2012 Author Posted October 13, 2012 @kylomas: stringlen ahhhh that was it!Thank you!
water Posted October 13, 2012 Posted October 13, 2012 amakrkr,the problem with your script was, that you were using StderrRead where you should have used StdOutRead. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
kylomas Posted October 13, 2012 Posted October 13, 2012 amakrkr, And that you were not reading all of the output kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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