
from subprocess import *c = 'dir' #Windowshandle = Popen(c, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True)print handle.stdout.read()handle.flush()
如果不使用
shell=True,则必须提供
Popen()列表而不是命令字符串,例如:
c = ['ls', '-l'] #Linux
然后将其打开而没有外壳。
handle = Popen(c, stdin=PIPE, stderr=PIPE, stdout=PIPE)print handle.stdout.read()handle.flush()
这是您可以从Python调用子流程的最手动,最灵活的方式。如果只需要输出,请执行以下 *** 作:
from subproccess import check_outputprint check_output('dir')要打开新的控制台GUI窗口并执行X:
import osos.system("start cmd /K dir") #/K remains the window, /C executes and dies (popup)欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)