Jump to content
Sign in to follow this  
schilbiz

Is DaveF ever going to write an Example for ConsoleRead.au3

Recommended Posts

weaponx

Just follow the example for StdoutRead

Share this post


Link to post
Share on other sites
schilbiz

I am new to AutoIt, can you explain exactly what the STDOUT flag value (2) is referring to?

The below is from http://www.autoitscript.com/autoit3/files/.../StdoutRead.htm

StdoutRead reads from the console standard output stream of a child process, which is normally used by console applications to write to the screen. During the call to Run for the child process you wish to read from the STD I/O parameter must have included the STDOUT flag value (2) for this function to work properly (see the Run function).

; Demonstrates StdoutRead()

#include <Constants.au3>

$foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1

$line = StdoutRead($foo)

If @error = -1 Then ExitLoop

MsgBox(0, "STDOUT read:", $line)

Wend

While 1

$line = StderrRead($foo)

If @error = -1 Then ExitLoop

MsgBox(0, "STDERR read:", $line)

Wend

MsgBox(0, "Debug", "Exiting...")

Share this post


Link to post
Share on other sites
MadBoy

Lets say you start a "CMD" window. In that window you type Ipconfig /all. That would display some information. How to get that information? You use the Flag 2 option in Run command to gather whatever is displayed by that command. More or less it would look like this:

Global $IpconfigOutputOnce

$ipconfig_output = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 2)
While 1
    $ipconfig_data = StdoutRead($ipconfig_output)
    If @error Then ExitLoop
    If $ipconfig_data Then
        $IpconfigOutputOnce &= $ipconfig_data
    Else
        Sleep(10)
    EndIf
WEnd
$IpconfigOutputOnce = StringStripWS($IpconfigOutputOnce, 7)

MsgBox(0, "Test", $IpconfigOutputOnce)

Does it makes sense? Of course you can then use StringStripCR, StringStripWS to get a nicer output or even diagnose what it says...

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites
schilbiz

Lets say you start a "CMD" window. In that window you type Ipconfig /all. That would display some information. How to get that information? You use the Flag 2 option in Run command to gather whatever is displayed by that command. More or less it would look like this:

Global $IpconfigOutputOnce

$ipconfig_output = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 2)
While 1
    $ipconfig_data = StdoutRead($ipconfig_output)
    If @error Then ExitLoop
    If $ipconfig_data Then
        $IpconfigOutputOnce &= $ipconfig_data
    Else
        Sleep(10)
    EndIf
WEnd
$IpconfigOutputOnce = StringStripWS($IpconfigOutputOnce, 7)

MsgBox(0, "Test", $IpconfigOutputOnce)

Does it makes sense? Of course you can then use StringStripCR, StringStripWS to get a nicer output or even diagnose what it says...

Okay I think so, to reitorate, anytime you want to read info from a cmd line using StdoutRead you will have to use Run to specifiy what you want to output in a MsgBox. Which is determined by what you set in Flag 2? Is that correct?

Share this post


Link to post
Share on other sites
MadBoy

Okay I think so, to reitorate, anytime you want to read info from a cmd line using StdoutRead you will have to use Run to specifiy what you want to output in a MsgBox. Which is determined by what you set in Flag 2? Is that correct?

MsgBox is just an example. You can for example put everything into a file, into an array, read it, check for special chars etc. Just replace the ipconfig /all command with lets say 'help' or 'ping google.com' etc. The flag 2 allows you to read whatever output the command had. There are multiple possibilities you can achieve with this.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites
schilbiz

MsgBox is just an example. You can for example put everything into a file, into an array, read it, check for special chars etc. Just replace the ipconfig /all command with lets say 'help' or 'ping google.com' etc. The flag 2 allows you to read whatever output the command had. There are multiple possibilities you can achieve with this.

Nice that sounds like a potentially handy tool. Thanks for the info.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.