how to run a DOS program without getting a box?

David Bolen db3l at fitlinxx.com
Thu Jan 18 03:00:50 EST 2001


Raymond Hettinger <othello at javanet.com> writes:

> Dan Rolander wrote:
(...)
> > >>> import os
> > >>> test = os.popen("c:\\test.bat")
> 
> Interesting that this works from the command prompt but fails inside the
> PythonWin
> environment.  The error message is:
>     WindowsError: [Errno 2] The system cannot find the file specified

This is a known problem with the os module implementation of popen in
Python 1.5.2 - it's actually not Python's fault, but a problem with an
underying issue with the Windows C popen() call - it won't work
without console handles, which a GUI application like Pythonwin
doesn't have.  (And actually, I believe that os.popen is less than
reliable under Windows versions other than NT, but I don't have a lot
of direct experience with that).

For Python 1.5.2, you can use the win32pipe.popen() call from the
win32all package, and it will work in both cases (and under Win9x),
but until the last one or two updates of the win32all package, one
difference is that you couldn't get the exit code of the process back
during the pipe close().  That works in the most recent releases.

As of Python 2.0, the os module works fine in both cases (it
incorporated the code from the win32all module when run under
Windows).

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



More information about the Python-list mailing list