How to get output from subprocess.Popen(). proc.stdout.readline() blocks, no data prints out

You obviously can use subprocess.communicate but I think you are looking for real time input and output.

readline was blocked because the process is probably waiting on your input. You can read character by character to overcome this like the following:

import subprocess
import sys

process = subprocess.Popen(
    cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE

while True:
    out =
    if out == '' and process.poll() != None:
    if out != '':

Leave a Comment