【发布时间】:2013-01-19 15:20:28
【问题描述】:
import os, subprocess
p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
print>>p.stdin, "echo hi"
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
print>>p.stdin, "python"
p.stdout.readline()
现在,如果我使用p.stdout.readline(),为什么我看不到 python shell?
另一方面,如果我从子进程中启动了另一个cmd 而不是python,我可以看到一个新的cmd shell 生成。
import os, subprocess
p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
print>>p.stdin, "echo hi"
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
print>>p.stdin, "cmd"
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
有什么区别?
【问题讨论】:
标签: python windows subprocess