Jump to content
itref88

Capturing EXE Console output and response

Recommended Posts

itref88

Hello,

I am trying to Run an exe that uses a console window class for its output.  I need to be able to interact with it by sending and receiving input to the window.

I am able to use Send("mycmdhere") just fine, but I haven't been able to figure out how to then wait for output back from the program, specifically "+ok".

I tried using the $STDOUT_CHILD with a while loop, but I am only ever seeing just blank lines returned for values, I can't seem to actually access the data displayed in the window of the running exe.

Can someone give me a quick idea on how to accomplish this, so that I can wait for the +ok response then continue on with the next?

Thanks in advance!

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Did you have a look at StdinWrite and StdoutRead?

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Zedna

As water said.

+ here is another simple example code (from older AutoIt 3.2.12.1 HelpFile):

; Demonstrates StdoutRead()
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

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

+here my similar example

#include <Constants.au3>
Dim $log, $output
$log=Run ( @ComSpec & ' /c ping www.seznam.czX', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
While 1
    $line = StdoutRead($log)
    If @error Then ExitLoop
    $output = $output & @CR & $line
Wend
While 1
    $line = StderrRead($log)
    If @error Then ExitLoop
    $output = $output & @CR & $line
Wend
MsgBox (0, 'Ping', $output)

 

Edited by Zedna

Share this post


Link to post
Share on other sites
caramen

 

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

×