From 03eb2e5498807786834933b54703b3b9f127e282 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Wed, 19 Apr 2017 08:42:09 -0700 Subject: py2/3 handle differences between py2 and 3 on reading/writing binary data to stdin/stdout --- test/redirection.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/redirection.py b/test/redirection.py index ffc76b5..ba35ed0 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) """) -- cgit v0.12