python 调用shell或windows命令

目前使用到的有两种方式: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')

 

posted @ 2015-06-30 16:31  药师Aric  阅读(1179)  评论(0编辑  收藏  举报