marekp Posted November 28, 2022 Posted November 28, 2022 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) EndIf consolewrite("PID: " & $iPID & @CRLF) Local $sout = "" while 1 sleep(100) $sout = StdoutRead($iPID) if @error then ConsoleWrite("ERROR (StdoutRead): " & @error & " " & $sout & @CRLF) ExitLoop endif if $sout <> 0 Then ConsoleWrite("Stdout: " & $sout & @CRLF) EndIf WEnd 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?
Danp2 Posted November 28, 2022 Posted November 28, 2022 Your parameters aren't in the correct location (missing parameter). Latest Webdriver UDF Release Webdriver Wiki FAQs
marekp Posted November 28, 2022 Author Posted November 28, 2022 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.
Danp2 Posted November 28, 2022 Posted November 28, 2022 Have you tried using $STDIO_INHERIT_PARENT instead of $STDIN_CHILD + $STDOUT_CHILD? Latest Webdriver UDF Release Webdriver Wiki FAQs
marekp Posted November 28, 2022 Author Posted November 28, 2022 4 minutes ago, Danp2 said: Have you tried using $STDIO_INHERIT_PARENT instead of $STDIN_CHILD + $STDOUT_CHILD? Yes, just now. It causes the application to terminate immediately and StdoutRead returns an error.
Danp2 Posted November 28, 2022 Posted November 28, 2022 You may need to adjust your code accordingly since StdoutRead will return an error if there is nothing to read. Latest Webdriver UDF Release Webdriver Wiki FAQs
marekp Posted November 28, 2022 Author Posted November 28, 2022 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).
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now