Skip to content

Python3 byte conversion and flushing #43

@vsajip

Description

@vsajip

Original report by Henry Perschk (Bitbucket: [Henry Perschk](https://bitbucket.org/Henry Perschk), ).


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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingminor

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions