How do I run an external system command on Windows?

David Bolen db3l at
Tue Sep 19 20:40:48 CEST 2000

noahspurrier at writes:

> Does this mean that the "commands" module will work under Python2.0
> and Windows?

No, unfortunately, since as you've noticed the command module makes
assumptions about the use Unix shell syntax.  It doesn't look like
this got revisited as part of 2.0, although I agree it might be the
logical place to isolate such dependencies.

> Thanks for the info. Maybe I'll go become a beta pig and download 2.0b.

Even prior to 2.0, it's not terribly difficult to isolate the OS check
in one place and just bind a name to the appropriate popen.  It
doesn't have to be much more than:

    import sys

    if sys.platform == "win32":
        import win32pipe
        mypopen = win32pipe.popen
        import os
        mypopen = os.popen

and then anywhere later that you need to create the pipe, just use
"mypopen".  If you've got a large, multi-module system, you could
stick this in some common module to avoid replicating the check.

-- David
 \               David Bolen            \   E-mail: db3l at  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \

More information about the Python-list mailing list