[python-win32] Programmatically capturing the text in a cmd

Roger Upole rwupole at msn.com
Tue Oct 31 00:08:32 CET 2006

Tim Roberts wrote:
> Roger Upole wrote:
>>Tony Cappellini wrote:
>>>In Windows XP, after a program has completed it's execution in a cmd
>>>Is there a way to *programmatically* capture the text that is in the
>>>scrollback buffer?
>>>I usually set my buffers to 10K lines or more, so there is a lot of text I'd
>>>like to capture.
>>>I want to do this programmatically, as opposed to using a mouse to mark and
>>The win32console module contains functions to read directly from a console buffer.
>>You can also use it to dynamically resize the output buffer.
> ... IF you are running inside that console window.  The OP wants to pull
> the console buffer from ANOTHER console window.  I don't think there is
> any way to do that, although I'm willing to be proven wrong.

win32console.AttachConsole allows this to be done.
Another alternative would be to create a small .bat file that runs the program
of interest, and then a python script to grab the console output.


More information about the Python-win32 mailing list