python call external program (WHAT THE?!)

Mike Steed MSteed at altiris.com
Thu Sep 16 14:04:16 EDT 1999


> From: Gordon McMillan [mailto:gmcm at hypernet.com]
> Sent: Thursday, September 16, 1999 11:38 AM
> To: Jeff; python-list at python.org; Ben Thomas
> Subject: Re: python call external program (WHAT THE?!)
> 
> 
> Jeff wrote:
> 
> > if you are trying to write portable code, I would go with the
> > suggestion below of using forward slashes in path names... if it
> > doesn't work by default under windows, you can write yourself a
> > simple function that *can* do it for you, and filter all your
> > pathnames through it-- the '/' is more natural anyway. have a
> > look at the 'os.path' module
> > <URL:http://www.python.org/doc/current/lib/module-os.path.html>.
> 
> Forward slashes work fine on Windows when the run through 
> the C library. When passed to os.system, however, they fail 
> messily, because that goes nowhere near the C library, and 
> the Windows API breaks up the string at each slash, thinking 
> they are options.

Just to be nit-picky, forward slashes work fine in argv[0] when passed to
os.system (at least on WinNT, don't know about Win9x).  So
os.system('c:/temp/junk.bat') works, but os.system('del c:/temp/*.*') and
the like will probably fail, depending on the executable.

Of course, it is safest and most portable to use os.path.

M.




More information about the Python-list mailing list