Jump to content

Interactive console application automation - Problem with stdout


Recommended Posts

I'm trying to automate an interactive Windows (C++) application. The application seems to using stdin/stdout, e.g.,

    std::cout << std::endl;
    std::cout << "Select Device:" << std::endl;
    for (UINT32 i = 0; i < devInfo.find_PnpDevice_Count; i++) {
        std::wcout << "  " << i + 1 << ") "
            << devInfo.find_PnpDevice_Info[i].dev_ModelName
            << std::endl;
    std::cout << "  q) quit" << std::endl;
    std::cout << "? ";
    std::cin >> key;
    if (key.c_str()[0] == 'q') {
        return -1;

... But I'm struggling to capture the application output in my trivial AutoIt script:

Local $iPID = Run("ActionParameters01.exe", "", $STDIN_CHILD + $STDOUT_CHILD)
if @error Then
    consolewrite("ERROR (Run): " & @error & " " & @extended & @CRLF)
consolewrite("PID: " & $iPID & @CRLF)

Local $sout = ""
while 1
    $sout = StdoutRead($iPID)
    if @error then
        ConsoleWrite("ERROR (StdoutRead): " & @error & " " & $sout & @CRLF)
    if $sout <> 0 Then
        ConsoleWrite("Stdout: " & $sout & @CRLF)

The script just returns a reasonable PID and the spins in the while loop till I terminate the application. I never see the output from the C++ code snip above (first thing the appliaction does). Confusingly - for me at least - if I remove the $STDOUT_CHILD option in 'Run' then the application output appears in the SciTE console.

What am I doing wrong?


Link to comment
Share on other sites

16 minutes ago, Danp2 said:

Your parameters aren't in the correct location (missing parameter).

Oops, sorry. I should have posted...

Local $iPID = Run("ActionParameters01.exe", "", @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)

I assume that's the parameter that you said was missing (@SW_SHOW)? Using this allows me to close the application easily. With @SW_HIDE the behaviour is the same - nothing captured from stdout) - but it's less convenient to terminate.

Link to comment
Share on other sites

28 minutes ago, Danp2 said:

You may need to adjust your code accordingly since StdoutRead will return an error if there is nothing to read.

Perhaps, but I don't see that relevant here since the error response is only when the application is closed down. My problem is capturing the stdout stream from the application whilst it's running (which is getting lost in the pipes somewhere).

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...