我正在使用子进程模块调用外部程序(plink.exe)来登录服务器;但是当我调用通信来读取输出时,它是阻塞的。代码如下:
import subprocess
process = subprocess.Popen('plink.exe hello@10.120.139.170 -pw 123456'.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print process.communicate() #block here
我知道该块是因为plink.exe
它仍在运行;但我需要在子进程终止之前读取输出。有没有办法做到这一点?