diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-04-19 08:42:09 -0700 |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2017-04-19 08:42:09 -0700 |
commit | 407a9011c05fa9490c64d4a549061c66745c6784 (patch) | |
tree | 449be58ecb4457544abccc57dc9aa11a6e12489c /test/redirection.py | |
parent | dc3bb12a7641bfb83b2b0c58b85058a8c8755b6a (diff) | |
download | scons-407a9011c05fa9490c64d4a549061c66745c6784.tar.gz |
py2/3 handle differences between py2 and 3 on reading/writing binary data to stdin/stdout
Diffstat (limited to 'test/redirection.py')
-rw-r--r-- | test/redirection.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/test/redirection.py b/test/redirection.py index ffc76b5f..ba35ed0f 100644 --- a/test/redirection.py +++ b/test/redirection.py @@ -32,11 +32,22 @@ test = TestSCons.TestSCons() test.write('cat.py', r""" import sys +PY3K = sys.version_info >= (3, 0) + try: - input = open(sys.argv[1], 'r').read() + input = open(sys.argv[1], 'rb').read() except IndexError: - input = sys.stdin.read() -sys.stdout.write(input) + if PY3K: + source = sys.stdin.buffer + else: + source = sys.stdin + input = source.read() + +if PY3K: + sys.stdout.buffer.write(input) +else: + sys.stdout.write(input) + sys.exit(0) """) |