changeset 46102:7ce24d3761e8

procutil: don't assign stdin to None, use os.devnull instead It will be painful to take care of procutil.stdin being None everywhere. Thanks to Yuya who recommended it.
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 10 Dec 2020 14:03:46 +0530
parents 49b6910217f9
children 3f82a915ab2a
files mercurial/utils/procutil.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/procutil.py	Thu Dec 10 13:51:56 2020 +0530
+++ b/mercurial/utils/procutil.py	Thu Dec 10 14:03:46 2020 +0530
@@ -126,7 +126,11 @@
     # a silly wrapper to make a bytes stream backed by a unicode one.
 
     # sys.stdin can be None
-    stdin = sys.stdin.buffer if sys.stdin else sys.stdin
+    if sys.stdin:
+        stdin = sys.stdin.buffer
+    else:
+        stdin = open(os.devnull, 'rb')
+        os.close(stdin.fileno())
     stdout = _make_write_all(sys.stdout.buffer)
     stderr = _make_write_all(sys.stderr.buffer)
     if pycompat.iswindows: