Python3 byte conversion and flushing

Create issue
Issue #43 resolved
Henry Perschk created an issue

Python 3.7.0, Sarge 0.1.5.post0 (through pip).

I followed the tutorial part "Interacting with child processes".

With Python 3, I had to execute the example slightly differently to get it to work. Please consider changing the docs, or telling me if I did something wrong :)

1) >>> p.stdin.write('Fred\n') has to be passed a bytes object (p.stdin.write(b'Fred\n')) (otherwise: TypeError: a bytes-like object is required, not 'str').

2) >>> p.stdin.write('Fred\n') >>> p.stdout.readline()

requires p.stdin.flush() to be called after writing to stdin, otherwise stdout will be empty.

There seems to be some kind of bug in Popen (see: https://stackoverflow.com/questions/27571305/subprocess-stdin-buffer-not-flushing-on-newline-with-bufsize-1), but even adding the suggested universal_newlines=True to the Command object didn't work for me (stdout empty, only works when flushing stdin).

Comments (3)

  1. Log in to comment