【发布时间】:2021-01-03 04:34:37
【问题描述】:
我正在从 python 的新 PowerShell 窗口中启动一个脚本,我想让该进程在后台运行,这样我就可以不断地与之交互。
我已尝试使用以下代码:
p = subprocess.Popen(['start powershell.exe', '-File', 'script.ps1']
shell = True,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
bufsize = 1,
encoding ='utf-8')
p.stdin.write('input1')
p.stdout.readline()
p.stdin.write('input2')
p.stdout.readline()
p.stdin.write('input3')
p.stdout.readline()
但是 p.stdin.write 什么都不做。 我该如何解决这个问题?
【问题讨论】:
-
我已经尝试过使用communicate(),但它不支持多重通信
-
“我可以持续与它互动” - 这是什么意思?
-
@IInspectable 就像代码说的:我有多个输入,我想将它们依次提供给子进程并每次都得到结果
标签: python windows powershell subprocess