[Scons-users] TypeError writing to stderror in MSCommon/Common.py

Mats Wichmann mats at wichmann.us
Wed Dec 4 09:41:52 EST 2019


On 12/4/19 6:38 AM, Joseph C. Brill wrote:
> There is a problem writing the stderr message returned by a subprocess.  
> The subprocess return message is a byte string while the write method 
> for the system stderr expects a string.
> 
> Python 3.7.4

> with popen.stderr: 
> *stderr = popen.stderr.read()*
>      # Extra debug logic, uncomment if necessary
> #     debug('get_output():stdout:%s'%stdout)
> #     debug('get_output():stderr:%s'%stderr)
>      if stderr:
>          # TODO: find something better to do with stderr;
>          # this at least prevents errors from getting swallowed.
> *sys.stderr.write(stderr)*
> 
> In Python 3, popen.stderr.read() returns a byte sequence while 
> sys.stderr.write(stderr) expects a string.

indeed... there's still some of this lurking around.  the choice of Py3 
subprocess to deliver stdin/stdout/stderr as bytes by default is ... 
irritating.  I keep advocating for us to give the text (aka 
universal_newlines) argument when we do subprocess.Popen, since we know 
in these cases were speaking to commands, not just reading arbitrary 
data, and Python knows the encoding of the system it's running on, so it 
has a better chance of getting it right than us guessing.  But the 
Python3 bytes story has left me so lacking in confidence so I'm not sure 
if I'm right. :(

we just had a go-round of similar problems with Solaris, where the 
result of checking the compiler version by asking it was bytes instead 
of str.


More information about the Scons-users mailing list