Sign in to follow this  
Followers 0
MattHiggs

processing rerturned text as process is executing

4 posts in this topic

A while back, I was investigating the "run" process, the opt_flags, and the different uses each had, when I ran across a very interesting post that had something I thought would be useful, but I didn't bookmark it and now cannot remember what the post was even about.:sweating:  It involved calling a command line command (lets say ipconfig /all for shits and giggles) using run and $STDOUT_CHILD opt_flag.  I then remember that, instead of waiting for the entirety of the process to finish and then returning all of the text that command prompt output (like what I usually do), this code called a do until loop which would read and process the text returned by the process in real time until the process ended.  I would like to be able to run ipconfig /all on a remote computer (using psexec) and be able to obtain only the MAC address associated with an IP that meets a particular schema (the IP addresses will always be static for the NICs for which I need the MAC) and then compares that to the information stored on a file on local computer containing the networking information (IP and associated MAC) to make sure values are still correct (like if a device breaks and gets replaced, MAC address would be different, but IP would still be static).  While located nowhere near it, the devices within this local area network are members of an active directory and connected to a domain controller, so gaining access will not be an issue (I can only hope).  But I guess my question becomes more "how does one only return a small portion of the total text returned by a run command without writing the information to another file?"  If I want the MAC address and IP for each NIC, I need to remove the portion of the text which indicates the device to which the given address belongs (I hope that makes sense).  Any advice anyone could give, or maybe even a snippet, and you will be my hero of the week.

 

Share this post


Link to post
Share on other sites



Script:

#include <AutoItConstants.au3>

Local $iPID = Run('c:\tmp\test.bat', "", @SW_SHOW, $STDOUT_CHILD)

Do
    Local $sOutput = StdoutRead($iPID)
    If $sOutput <> "" Then ConsoleWrite($sOutput)
    Sleep(10)
Until Not ProcessExists($iPID)

Batch file:

Quote

@echo off
FOR /L %%A IN (1,1,10) DO (
    ECHO %%A
    REM timeout /t 1 doesn't work in non-interactive scripts
    PING 1.1.1.1 -n 1 -w 1000 > NUL
)

What did I win?

1 person likes this

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

If I do this 

#include <AutoItConstants.au3>

Local $iPID = Run('ipconfig /all', "", @SW_SHOW, $STDOUT_CHILD)
Do
    Local $sOutput = StdoutRead($iPID)
    If $sOutput <> "" Then ConsoleWrite("output:"&$sOutput)
    Sleep(10)
Until Not ProcessExists($iPID)

I get the results:

output:
Windows IP Configuration

   Host Name . . . . . . . . . . . . : compname
   Primary Dns Suffix  . . . . . . . : 
output:   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : domain.name

This means it ran through the loop twice, each returning a fragment. AND the process terminated before it got the detailed data on the adapters. Unless you are concatenating the results from StdoutRead (or "peaking"), you may be best waiting till ipconfig the process terminates before looking at the data.

As well as it truncated the data, you may want to call StdOutRead once more after the process terminates.

#include <AutoItConstants.au3>

Local $iPID = Run('ipconfig /all', "", @SW_SHOW, $STDOUT_CHILD)
Do
    Local $sOutput = StdoutRead($iPID)
    If $sOutput <> "" Then ConsoleWrite("output:"&$sOutput)
    Sleep(10)
Until Not ProcessExists($iPID)
    $sOutput = StdoutRead($iPID)
    If $sOutput <> "" Then ConsoleWrite("output after termination:"&$sOutput)

 

1 person likes this

Share this post


Link to post
Share on other sites

THanks a ton you guys.  Really appreciate the input.  Heros for the week: TurionAltec  and SadBunny .

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  
Followers 0