By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
rbt
Tian 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?


name your scripts with .pyw extensions instead of .py extensions
Jul 18 '05 #2

P: n/a
Or launch it with pythonw.exe ( on windows )

Sorcier glouton http://sorcier-glouton.ath.cx
"rbt" <rb*@athop1.ath.vt.edu> a écrit dans le message de news:
d2*********@solaris.cc.vt.edu...
Tian 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?


name your scripts with .pyw extensions instead of .py extensions

Jul 18 '05 #3

P: n/a
On 29 Mar 2005 13:23:55 -0800, "Tian" <wa*********@gmail.com> 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

os.system(cmdstring)

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.

Regards,
Bengt Richter
Jul 18 '05 #4

P: n/a
this is very useful, thanks very much!

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.