Capture the stderr from 'tar --version' call as otherwise error messages
spill onto user's terminal unnecessarily (e.g. on NetBSD where tar does
not support long options). While at it, refactor the code to use
communicate() instead of reinventing the wheel.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
test/lit.cfg.py | ||
---|---|---|
99 ↗ | (On Diff #177238) | If you don't need stderr, remove stderr=subprocess.PIPE, subprocess.Popen followed by communicate() can be replaced by check_output if 'GNU tar' in sout: does not in Python 3 as sout would have type bytes, not str |
test/lit.cfg.py | ||
---|---|---|
99 ↗ | (On Diff #177238) | I think as Fangrui suggested subprocess.check_output(["/tmp/foo"], stderr=subprocess.STDOUT) is better than subprocess.Popen followed by communicate() and wait(). |
Sorry, it seems that my reply didn't go through.
test/lit.cfg.py | ||
---|---|---|
99 ↗ | (On Diff #177238) | I need to silence stderr. Given that /dev/null is not portable, and subprocess.DEVNULL requires py3.3+, capturing it is the simplest solution. check_output() will throw when tar doesn't support version, i.e. it would break NetBSD completely instead of silencing the error. I'll fix the type mismatch. |
test/lit.cfg.py | ||
---|---|---|
99 ↗ | (On Diff #177238) | Oh sorry I didn't know that check_output throws if a subprocess exits with non-zero exit code. |
test/lit.cfg.py | ||
---|---|---|
101 ↗ | (On Diff #177250) | LG, but serr can be replaced by _ if it is not used. |
test/lit.cfg.py | ||
---|---|---|
100 ↗ | (On Diff #177265) | Maybe a silly question, but is this OK to remove this line? |
test/lit.cfg.py | ||
---|---|---|
100 ↗ | (On Diff #177265) | Yes. communicate() waits on the process. |