Jump to content

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


 Share

Recommended Posts

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...")

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

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...