Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

how to run a DOS program without getting a box?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


rwd at cableinet

Jan 16, 2001, 5:00 PM

Post #1 of 5 (655 views)
Permalink
how to run a DOS program without getting a box?

Hi all,

I have tried both os.system() and the exec~ calls, and they all cause
the Windows console to display when running a command-line program (in
my case, to play a soundfile I don't need to see the screen messages).
Is there a way to suppress this? Other languages, such as tcl/tk and GNU
Octave manage this fine. I'm using Python 2.0 under Windows2000 (sp1),
with IDLE.


Richard Dobson




--
Test your DAW with my Soundcard Attrition Page!
http://www.bath.ac.uk/~masrwd (LU: 3rd July 2000)
CDP: http://www.bath.ac.uk/~masjpf/CDP/CDP.htm (LU: 23rd February 2000)


richard_chamberlainREMOVE at ntlworld

Jan 17, 2001, 12:13 AM

Post #2 of 5 (640 views)
Permalink
how to run a DOS program without getting a box? [In reply to]

There is a file called pythonw.exe which is python without the command box.

Richard

Richard Dobson <rwd [at] cableinet> wrote in message
news:3A64E195.ECA51312 [at] cableinet
> Hi all,
>
> I have tried both os.system() and the exec~ calls, and they all cause
> the Windows console to display when running a command-line program (in
> my case, to play a soundfile I don't need to see the screen messages).
> Is there a way to suppress this? Other languages, such as tcl/tk and GNU
> Octave manage this fine. I'm using Python 2.0 under Windows2000 (sp1),
> with IDLE.
>
>
> Richard Dobson
>
>
>
>
> --
> Test your DAW with my Soundcard Attrition Page!
> http://www.bath.ac.uk/~masrwd (LU: 3rd July 2000)
> CDP: http://www.bath.ac.uk/~masjpf/CDP/CDP.htm (LU: 23rd February 2000)


dan.rolander at marriott

Jan 17, 2001, 6:13 AM

Post #3 of 5 (642 views)
Permalink
how to run a DOS program without getting a box? [In reply to]

Richard (and Richard),

pythow.exe is fine if you want to run a python script without starting a
console window, but if you want to launch external programs from within a
python script here is how to do it:

If you are starting a Windows application, first get the Win32 extensions at
http://www.activestate.com/Products/ActivePython/win32all.html. Then import
win32api and use WinExec() like this:

>>> import win32api
>>> win32api.WinExec("notepad")

If you want to launch a DOS application, and don't want a console window but
you do want to capture stdout, you can just import os and use popen() like
this:

>>> import os
>>> test = os.popen("c:\\test.bat")
>>> for L in test.readlines():
... print L
...

D:\Documents\Dan\PythonScripts\projects\pineapple>echo This is a test
This is a test

I hope this helps you!
Dan

----- Original Message -----
From: "Richard Chamberlain" <richard_chamberlainREMOVE [at] ntlworld>
Newsgroups: comp.lang.python
To: <python-list [at] python>
Sent: Wednesday, January 17, 2001 2:13 AM
Subject: Re: how to run a DOS program without getting a box?


> There is a file called pythonw.exe which is python without the command
box.
>
> Richard
>
> Richard Dobson <rwd [at] cableinet> wrote in message
> news:3A64E195.ECA51312 [at] cableinet
> > Hi all,
> >
> > I have tried both os.system() and the exec~ calls, and they all cause
> > the Windows console to display when running a command-line program (in
> > my case, to play a soundfile I don't need to see the screen messages).
> > Is there a way to suppress this? Other languages, such as tcl/tk and GNU
> > Octave manage this fine. I'm using Python 2.0 under Windows2000 (sp1),
> > with IDLE.
> >
> >
> > Richard Dobson
> >
> >
> >
> >
> > --
> > Test your DAW with my Soundcard Attrition Page!
> > http://www.bath.ac.uk/~masrwd (LU: 3rd July 2000)
> > CDP: http://www.bath.ac.uk/~masjpf/CDP/CDP.htm (LU: 23rd February 2000)
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


othello at javanet

Jan 17, 2001, 9:56 PM

Post #4 of 5 (642 views)
Permalink
how to run a DOS program without getting a box? [In reply to]

Dan Rolander wrote:

> If you are starting a Windows application, first get the Win32 extensions at
> http://www.activestate.com/Products/ActivePython/win32all.html. Then import
> win32api and use WinExec() like this:
>
> >>> import win32api
> >>> win32api.WinExec("notepad")

How do you call built-in DOS commands or pass arguments?
win32api.WinExec("time 23:30") doesn't do the trick :(


> If you want to launch a DOS application, and don't want a console window but
> you do want to capture stdout, you can just import os and use popen() like
> this:
>
> >>> 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


db3l at fitlinxx

Jan 18, 2001, 1:00 AM

Post #5 of 5 (641 views)
Permalink
how to run a DOS program without getting a box? [In reply to]

Raymond Hettinger <othello [at] javanet> 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 /
| FitLinxx, Inc. \ Phone: (203) 708-5192 |
/ 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
\-----------------------------------------------------------------------/

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.