1. os.system(cmd)
>>> import os
>>> os.system('date')
Fri Apr 13 11:00:47 DST 2018
2. os.popen(cmd)
>>> import os
>>> now = os.popen('date')
>>> now.read() # 读取管道
Fri Apr 13 11:00:47 DST 2018
3. subprocess
>>> import subprocess
>>> now = subprocess.Popen('date', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # 线程
>>> now.stdout.read()
Fri Apr 13 11:00:47 DST 2018
网友评论