How do I shell-out on Win32 systems with python?

Tim Peters tim_one at email.msn.com
Mon Oct 11 19:10:10 EDT 1999


[yinger]
> I know that on Unix systems you can use the commands  or the popen
> modules.
>
> What do I have to do to get the output from a command (like 'dir', or a
> batch file) executed on a Win32 system?

It's a crap shoot.  If you're going to do this a lot, buy and install a
"real shell" (like 4NT).  os.popen() sometimes works.  The win32pipe module
(in Mark Hammond's PythonWin extension) works more often.  Commands like
"dir" are especially risky, because they're shell builtins and the Windows
shells are, umm, challenged.  Sometimes it's effective to hide the "real
command" in a .bat file and use os.popen() to run the latter.  For
educational laughs, bring up the Tcl help file and look at

    Tcl Built-In Commands -> exec

Tcl has (literally) thousands of lines of internal code trying to make this
stuff work well under Windows, and they still have pages of warnings about
things that can go wrong.

keep-your-finger-near-the-reboot-button-ly y'rs  - tim






More information about the Python-list mailing list