1.os模塊
import os os.system(commad) 返回0或1,0代表正常;1代表異常
2.os.popen()方法不僅執行命令而且返回執行后的信息對象(常用於需要獲取執行命令后的返回信息),是通過一個管道文件將結果返回。
import os os.popen()
3.subprocess模塊
from subprocess import Popen resultsCommond = Popen(rm_command,stdout=PIPE, stderr=PIPE,stdin=PIPE,shell=True) shell:如果該參數為 True,將通過操作系統的 shell 執行指定的命令。 獲取標准輸出:data = resultsCommond.stdout.read() 獲取錯誤輸出:data = resultsCommond.stderr.read()