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

T

Tian

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?
 
R

rbt

Tian said:
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
 
B

Bengt Richter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top