Jump to content

getting value from run(...) command


amakrkr
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...