在Python中调用系统命令有以下几种方式:
1、os.system(command) : 返回一个整型,表示调用的执行状态码,不能获取程序的输出
2、os.popen(command) : 可以获取程序执行的结果和输出
Python method popen() opens a pipe to or from command.The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'.
3、commands: 适用于python2,在python3中已经被移除,推荐适用subprocess
import commands;
commands.getstatusoutput(command)
4、subprocess.call(command, shell=True) :可以获取程序返回结果