python subprocess Popen readline() 会卡住,请帮帮我

问题描述 投票:0回答:0

我用

Popen
来执行一个字符串
cmd
cmd
使用 ascp 发送文件。想用
readline()
读取发送进度的百分比,但是每次都会卡在
readline

import subprocess

cmd = "ascp xxxxxxxxx xxxxxxx"

ps = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderror=subprocess.PIPE)

while ps.poll() is None():
    line = ps.stdout.readline()    # I can not get output during transfer, it will stuck here 
    print(line)

ps.wait()
python subprocess
© www.soinside.com 2019 - 2024. All rights reserved.