How to execute a cmd line program without invoking console window?

Bengt Richter bokr at
Wed Mar 30 03:34:33 CEST 2005

On 29 Mar 2005 13:23:55 -0800, "Tian" <wangtianthu at> wrote:

>In Windows, I have been simply using os.system() to run command line
>program in python. but there will be a black console window. How can I
>run the program without invoking that window? i guess there are some
>function with which I can redirect the output?
Instead of


try using

    the_output = os.popen(cmdstring).read()

to run the command and get the output. There are other variations
to capture stderr or combined output etc.

If you want to do popen(cmdstring) from a python program that does not _itself_
have a console window, look into running _that_ using the pythonw.exe (note "w")
interpreter instead of the python.exe interpreter, as others have mentioned.

Bengt Richter

More information about the Python-list mailing list