I’m tring to capture de information shown in a command prompt (cmd window) at a specific moment and send it to a text file.
I have an app in C/C++ that is launched by a batch script like this:
c:\myProgramInC.exe
echo "Ending with error"
PAUSE
myProgramInC.exe is always running (with an infinite loop) so if my script gets to the echo command it means my app ended with an abend.
What I want to get is the previous lines before the end execution of the script since my myProgramInC.exe always prints info about what is going on and it would be very useful to see what it was happening when the error ocurred. Something like this
c:\myProgramInC.exe
**** Execution of process to get te previous N lines in the command prompt ****
echo "Ending with error"
PAUSE
I know the cmd window have a buffer and I’ve been thinking to capture all of this data from such buffer. It is any way to get this info as text to store it in a file?
I’v been trying with something more professional shuch as to make a dump of the memory with ProcDump but since I have various myProgramInC.exe running at the same time (each one stored in a different location) I just get the message “Multiple processes match the specified name.” and the rest of the options are just not useful for me since my app doesn’t get unresponsive, it simply ends.
Any ideas?
You can do this in C easily enough, using the ReadConsoleOutputCharacter function.