由于某种原因,在调用 Powershell 脚本并且命令的输出不是动态的之后,Popen 无法退出。
我是否遗漏了代码中的某些内容:
sCmd = "powershell -file somefile.ps1"
process = subprocess.Popen(sCmd.strip(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
p = process.communicate()
sys.stdout.write(p[0])
sys.stderr.write(p[1])
sys.stdout.flush()
if(len(p[0]) == 0 and isinstance(process.poll(), int)):
break
if(process.wait() != 0):
os._exit(1)