- try to make
jython
stdout/stderr unbuffered, pass -u
command-line argument
- if you set
stderr=PIPE
then you should read it, otherwise a deadlock may occur if the child process fills the OS pipe buffer corresponding to its stderr. You could redirect it to stdout: stderr=STDOUT
- set Python side buffering explicitely:
bufsize=1
(line-buffered)
- use
iter(p.stdout.readline, '')
to avoid read-ahead bug on Python 2
from subprocess import Popen, PIPE, STDOUT
p = Popen(['jython', '-u', ...], stdin=PIPE, stdout=PIPE, stderr=STDOUT,
bufsize=1)
print >>p.stdin, 'test="hallo"' #NOTE: it uses `os.linesep`
print >>p.stdin, 'print test'
p.stdin.close() # + implicit .flush()
for line in iter(p.stdout.readline, ''):
print line, #NOTE: comma -- softspace hack to avoid duplicate newlines
p.stdout.close()
rc = p.wait()