From 4a5b924d375461444c4fe2f61942a3febf37af1d Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 18 Sep 2016 03:07:51 +0200 Subject: [PATCH] Do not attempt to close stdin/stdout file objects --- scour/scour.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index 8f32367..5801962 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3758,9 +3758,13 @@ def start(options, input, output): out_string = scourString(in_string, options).encode("UTF-8") output.write(out_string) - # Close input and output files - input.close() - output.close() + # Close input and output files (but do not attempt to close stdin/stdout!) + if input is not sys.stdin: + if hasattr(input, 'buffer') and input is not sys.stdin.buffer: + input.close() + if output is not sys.stdout: + if hasattr(output, 'buffer') and output is not sys.stdout.buffer: + output.close() end = walltime()