3

I'm in need of setting the stderr stream in a Popen call to line-buffered. I discovered the bufsize argument, but it doesn't say which of the 3 (stdin, stdout, stderr) files it's actually applied to.

  • Which file does the bufsize argument modify?
  • How do I modify the other file buffering modes?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

1 Answers1

3

Use the source, Luke :-) /usr/lib/python2.7/subprocess.py:

if p2cwrite is not None:
    self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
if c2pread is not None:
    if universal_newlines:
        self.stdout = os.fdopen(c2pread, 'rU', bufsize)
    else:
        self.stdout = os.fdopen(c2pread, 'rb', bufsize)
if errread is not None:
    if universal_newlines:
        self.stderr = os.fdopen(errread, 'rU', bufsize)
    else:
        self.stderr = os.fdopen(errread, 'rb', bufsize)

So it seems it uses bufsize in all of them, no way to be specific.

tokland
  • 66,169
  • 13
  • 144
  • 170