Jump to content

Capturing EXE Console output and response


Recommended Posts

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!

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Did you have a look at StdinWrite and StdoutRead?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

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

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's 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

 

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