diff mercurial/hook.py @ 14993:e5b2ee5157ae stable

hook: be prepared for __stdout/err__ not having fileno() it may have been replaced, see https://bitbucket.org/tortoisehg/thg/issue/937
author Idan Kamara <idankk86@gmail.com>
date Sat, 30 Jul 2011 23:41:10 +0300
parents 58f97dcbd550
children f6a737357195
line wrap: on
line diff
--- 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'):