From 203fe326d477b44460f03eaae9cc773b44b07dcd Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sun, 22 Mar 2015 00:15:54 +0000 Subject: [PATCH] [python] fix subprocess shell pipeline --- python/tests/compatibility_test.py | 7 ++++--- python/tests/roundtrip_test.py | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/python/tests/compatibility_test.py b/python/tests/compatibility_test.py index e5d3f41..500eeed 100755 --- a/python/tests/compatibility_test.py +++ b/python/tests/compatibility_test.py @@ -47,9 +47,10 @@ for filename in INPUTS.splitlines(): if diff_q(uncompressed, expected) != 0: sys.exit(1) # Test the streaming version - p = Popen('"%s" -d > "%s"' % (BRO, uncompressed), shell=True, stdin=PIPE) with open(filename, "rb") as infile: - data = infile.read() - p.communicate(data) + p = Popen('"%s" -d' % BRO, stdin=infile, stdout=PIPE, shell=True) + output = p.communicate()[0] + with open(uncompressed, "wb") as outfile: + outfile.write(output) if diff_q(uncompressed, expected) != 0: sys.exit(1) diff --git a/python/tests/roundtrip_test.py b/python/tests/roundtrip_test.py index c48db11..5ef4ba3 100755 --- a/python/tests/roundtrip_test.py +++ b/python/tests/roundtrip_test.py @@ -33,16 +33,18 @@ for filename in INPUTS.splitlines(): print('Roundtrip testing of file "%s"' % os.path.basename(filename)) compressed = os.path.splitext(filename)[0] + ".bro" uncompressed = os.path.splitext(filename)[0] + ".unbro" - with open(filename, "rb") as infile: - data = infile.read() call('"%s" -f -i "%s" -o "%s"' % (BRO, filename, compressed), shell=True) call('"%s" -f -d -i "%s" -o "%s"' % (BRO, compressed, uncompressed), shell=True) if diff_q(filename, uncompressed) != 0: sys.exit(1) # Test the streaming version - p = Popen("%s | %s -d > %s" % (BRO, BRO, uncompressed), stdin=PIPE, - shell=True) - p.communicate(data) + with open(filename, "rb") as infile: + p1 = Popen(BRO, stdin=infile, stdout=PIPE, shell=True) + p2 = Popen("%s -d" % BRO, stdin=p1.stdout, stdout=PIPE, shell=True) + p1.stdout.close() + output = p2.communicate()[0] + with open(uncompressed, "wb") as outfile: + outfile.write(output) if diff_q(filename, uncompressed) != 0: sys.exit(1)