In Python 3, here's a solution using two separate files, onewhich takes a producer (for testing)command off the command line and one adelivers real-time receiver. The output is decoded nicely decoded strings as a normal looking stringthey are received.
ProducerReceiver (dummy_outputreceiver.py):
import timesubprocess import sys forcmd i= insys.argv[1:] p range= subprocess.Popen(5cmd, stdout=subprocess.PIPE) for line in p.stdout: print("hello"received: {}".format(i)) sys.stdoutline.flushrstrip() time.sleepdecode(1"utf-8"))) ReceiverExample simple program that could generate real-time output (receiverdummy_out.py):
import subprocess time cmd = 'pythonimport dummy_output.py'.split()sys p = subprocess.Popen(cmd, stdout=subprocess.PIPE) for linei in p.stdoutrange(5): print("received:"hello {}".format(linei)) sys.rstripstdout.flush() time.decodesleep("utf-8"))1) Output:
$python receiver.py python dummy_out.py received: hello 0 received: hello 1 received: hello 2 received: hello 3 received: hello 4