在Python中执行系统命令有os.system().os.popen().commands.getstatusoutput().subprocess.Popen等 1.os.system() Python中关于os.system的描述: >>> import os >>> help(os.system) system(command) -> exit_status Execute the command (a string) in a subshell.
import os, subprocess # os.system('dir') #执行系统命令,没有获取返回值,windows下中文乱码 # result = os.popen('dir') #执行系统命令,返回值为result# res = result.read()# for line in res.splitlines():# print(line ) #用subprocess库获取返回值.# p = subprocess.Popen('dir', shell=True, stdout=