how to run a DOS program without getting a box?

Dan Rolander dan.rolander at marriott.com
Wed Jan 17 08:13:21 EST 2001


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.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
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.co.uk> wrote in message
> news:3A64E195.ECA51312 at cableinet.co.uk...
> > 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
>





More information about the Python-list mailing list