Jump to content
Sign in to follow this  
amakrkr

getting value from run(...) command

Recommended Posts

amakrkr

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!

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
amakrkr

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 by amakrkr

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×