Reprint: http://blog.csdn.net/b_h_l/article/details/12654749
The first type: Using Os.system ()
Import OS
Os.system ('cat/etc/profile')
The second type: Using Os.popen ()
= Os.popen ('cat/proc/cpuinfo') print output.read ()
The object that is returned by Os.popen () is a file read that reads the read () operation to see the output that is executed
The third type: using commands
Import Commands (status,output)=commands.getstatusoutput ('Cat/etc/profile') Print Statusprint output#===============output in Linux=commands.getoutput ('Cat/etc/profile') Status=commands.getstatus ('Cat/etc/profile')#===============You can also use the window (status,output)=commands.getstatusoutput ('dir') Print Statusprint output
Summary: The first is the most common, but sometimes need to master the results of command execution, at this time we can use the third
Python methods for executing system commands Os.system (), Os.popen (), commands