hook: be prepared for __stdout/err__ not having fileno() stable
authorIdan Kamara <idankk86@gmail.com>
Sat, 30 Jul 2011 23:41:10 +0300
branchstable
changeset 14993 e5b2ee5157ae
parent 14992 188936b334b1
child 14994 a115b5ee9c63
hook: be prepared for __stdout/err__ not having fileno() it may have been replaced, see https://bitbucket.org/tortoisehg/thg/issue/937
mercurial/hook.py
--- a/mercurial/hook.py	Sat Jul 30 21:04:14 2011 +0300
+++ b/mercurial/hook.py	Sat Jul 30 23:41:10 2011 +0300
@@ -134,12 +134,16 @@
 
     oldstdout = -1
     if _redirect:
-        stdoutno = sys.__stdout__.fileno()
-        stderrno = sys.__stderr__.fileno()
-        # temporarily redirect stdout to stderr, if possible
-        if stdoutno >= 0 and stderrno >= 0:
-            oldstdout = os.dup(stdoutno)
-            os.dup2(stderrno, stdoutno)
+        try:
+            stdoutno = sys.__stdout__.fileno()
+            stderrno = sys.__stderr__.fileno()
+            # temporarily redirect stdout to stderr, if possible
+            if stdoutno >= 0 and stderrno >= 0:
+                oldstdout = os.dup(stdoutno)
+                os.dup2(stderrno, stdoutno)
+        except AttributeError:
+            # __stdout/err__ doesn't have fileno(), it's not a real file
+            pass
 
     try:
         for hname, cmd in ui.configitems('hooks'):