How to get text from cmd using autoIT

124 views Asked by At

I am new to AutoIT and would like to know if there is any way of getting the text from the output. Please refer the screenshot for more clarification.

enter image description here

1

There are 1 answers

10
Attila On

Where that screenshot comes from? Is that a separate application, or a command line (console)? You mentioned "from the output", so StdoutRead might be the solution (without knowing more details).

** UPDATE
Based on the answer - this is a separate app, which seems to write to standard output. You might try the following

If you want to process the text whenever it appears, process it inside the while loop. In that case keep in mind, some text might be even being printed, means they might be incomplete.

#include <AutoItConstants.au3>
$App="C:\Your\Path\To\App.exe"
$PID=Run(@ComSpec & ' /C "' &  $App & '"',@TempDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)

$output=""

While ProcessExists($PID)
    $output &= StdoutRead($PID)
    Sleep(100)
WEnd

MsgBox(0,"Ready","Read from other app's StdOut: " & @CRLF & $output)

** UPDATE 2 Seems you would like to interact with your application not just read from there (according to your comment below). Using Send() function is not the best choice as that sends the text to the window which is in the front. You have to start the application with Run() which gives you its process ID, then use StdinWrite() and StdoutRead() to send/receive texts. Here is a bare example returning your domain and username:
result read from stdout

#include <Constants.au3>
Local $PID = Run("cmd.exe", @SystemDir, @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($PID,"whoami" & @CRLF) 
$output="" 
While ProcessExists($PID) 
    $output &= StdoutRead($PID) 
    Sleep(1000) 
WEnd 
MsgBox(0,"Ready","Read from other app's StdOut: " & @CRLF & $output)