pager: don't page stderr if it's being redirected (issue2541) stable
authorBrodie Rao <brodie@bitheap.org>
Tue, 04 Jan 2011 00:24:34 +1100
branchstable
changeset 13642 994510694b1d
parent 13641 2420cb1ea1d6
child 13648 d943efb9701f
child 13651 9777df929035
child 13671 47f11b52021b
pager: don't page stderr if it's being redirected (issue2541)
hgext/pager.py
--- a/hgext/pager.py	Fri Mar 11 11:14:21 2011 +0100
+++ b/hgext/pager.py	Tue Jan 04 00:24:34 2011 +1100
@@ -59,14 +59,17 @@
 
 def _runpager(p):
     if not hasattr(os, 'fork'):
-        sys.stderr = sys.stdout = util.popen(p, 'wb')
+        sys.stdout = util.popen(p, 'wb')
+        if sys.stderr.isatty():
+            sys.stderr = sys.stdout
         return
     fdin, fdout = os.pipe()
     pid = os.fork()
     if pid == 0:
         os.close(fdin)
         os.dup2(fdout, sys.stdout.fileno())
-        os.dup2(fdout, sys.stderr.fileno())
+        if sys.stderr.isatty():
+            os.dup2(fdout, sys.stderr.fileno())
         os.close(fdout)
         return
     os.dup2(fdin, sys.stdin.fileno())