在python中运行cmd命令

import sys
reload(sys)
sys.setdefaultencoding('utf8')

import subprocess
import os
import commands

#os.system('cmd1 && cmd2')
cmd1 = "cd ../"
cmd2 = "ls"
cmd = cmd1 + " && " + cmd2

#如下两种都可以运行
subprocess.Popen(cmd, shell=True)
subprocess.call(cmd,shell=True)

猜你喜欢

转载自blog.csdn.net/buside/article/details/82876211