python 调用shell或windows命令

时间:2021-08-27 17:00:56

目前使用到的有两种方式:os.system()和os.popen()

import os
os.system('cd e:cjx') #调用后返回执行结果状态

如果想获得返回结果,则使用以下方式:

import os
res = os.popen('dir').readlines()
print(res)

 如果要连续执行多个命令:

import os
os.system('e: & cd e:\cjx & dir')

相关文章