[Tutor] commands versus subprocess, I'm confused

Alan Gauld alan.gauld at btinternet.com
Fri Dec 26 15:28:57 CET 2008


"Emad Nawfal (عماد نوفل)" <emadnawfal at gmail.com> wrote

>> proc = subprocess.Popen('python3.0 hello.py',
>>                       shell=True,
>>                       stdout=subprocess.PIPE,
>>                       )
>> stdout_value = proc.communicate()[0]

> Thank you Kent.
> It works, but isn't the commands module much simpler?  I don't know 
> why it's
> no more available in Python3.0

commands was one of many different ways to access command ouitput.
Subprocess was designed to replace all of them and provide a single
consistent mechanism.

So, yes we lost some simplicity but gained consistency.
You no longer need to figure out whether its best to use
os,system, os.popen(and which version of popen), os.spawn, commands 
etc

You just use subprocess...
HTH,
Alan G 




More information about the Tutor mailing list