os.popen vs os.system

Peter Hansen peter at engcorp.com
Tue May 17 14:25:12 EDT 2005


rbt wrote:
> Is it more appropriate to use os.popen or os.system on a windows XP 
> client? I'm calling the operting system's shutdown function like this:
> 
> restart = os.popen(shutdown -r -f)
> print restart.read()
> restart.close()

I don't think there's any significant difference between the above 
(assuming you add in the missing quotation marks) and 
os.system('shutdown -r -f'), except that the os.system() approach is 
shorter and more readable if you are simply discarding or printing the 
output like that.

 > If it matters, I'm doing this remotely over sockets.

You can't be doing exactly that, since there are no sockets involved... 
do you mean the above call is executed -- on the receiving end -- after 
some signal is received via a socket in another part of the code? 
That's not going to have any effect on things...

-Peter



More information about the Python-list mailing list