I have a long running console application that starts with Windows, or that may be started by the app I'm writing.
I have had limited success sending keys to the console application, and don't even know where to start for reading output from it. Is reading the output from an console application that isn't even started by the requesting application even possible?
Anyways, two questions...
How can I emulate a "return" key? (Here is what I have to send specific keys to the application, and the app does receive the keys, but I can't seem to find how to emulate the ENTER key.
do {
hwndCurrentWindow = FindWindowA("ConsoleWindowClass", "My Other Console App");
if (hwndCurrentWindow == 0) {
break;
}
iStringLen = GetWindowTextW (hwndCurrentWindow, wcharWindowText, 500);
if (iStringLen == 0) {
continue;
}
SetActiveWindow(hwndCurrentWindow);
printf("Sending '?'");
SendMessage(hwndCurrentWindow, WM_CHAR, '?', 0);
// '?' shows up in console app
printf("Sending 'a'");
SendMessage(hwndCurrentWindow, WM_CHAR, 'a', 0);
// 'a' shows up in console app.
//printf("Sending RETURN");
//SendMessage(hwndCurrentWindow, WM_CHAR, VK_RETURN, 0);
// nothing happens
break;
} while (hwndCurrentWindow);
How can I read data from the console application? (If the other console application didn't run continuously I would just write the output to a file and read that in... heck that may still work)
I have looked at a handful of options, but many of the ones I read are for C#, and sadly I don't have the luxury of changing languages. Are there any similar options for C++?
Collect stdout output from a console app with C++ This one doesn't work because the application doesn't quit. So it just hangs and waits. Continuously adding more to the buffer.
Capturing an c# executable output from another C# program
Thanks for any help you can provide!