How do I send keystrokes to a console window in Windows XP?

Peter Hansen peter at
Wed Jul 20 03:50:33 CEST 2005

RTG wrote:
> With this capability, other possibilities open up.
> Is there a way to read the output from the from the console window?
> For example, how can we capture the output of the dir command?

Normally one does that using a call to things like os.popen, or using 
the new subprocess module.

If that's not suitable (if for some bizarre reason you really do want to 
pick up the output of "dir" after someone has run it manually in the 
console, and I can't imagine why you would want that), then search in 
the list archives for a recent thread that did investigate just that 
issue: how to capture text from a console window in Win32.  I don't 
recall the answer but I'm sure you can find it.


More information about the Python-list mailing list