subprocess.Popen在不同的控制台中

subprocess.Popen在不同的控制台中,第1张

subprocess.Popen在不同的控制台
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)


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5642720.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存