Windows: using hg executable from an IDE results in python errors

Steve Borho steve at
Thu Mar 20 14:14:19 CDT 2008

On Thu, 2008-03-20 at 11:20 -0700, Howard Ha wrote:
> Hi everyone,
> I'm completely new to Mercurial, but a longtime cvsnt user considering 
> moving our entire team to Hg.
> We do web development on Windows boxes using PHPEd as our IDE, and 
> luckily that tool has the ability to integrate with external apps by 
> executing "shell scripts" (they use this to integrate svn and cvs with 
> the IDE).  The added benefit of using this over just using tortoiseHg is 
> that we can assign keyboard shortcuts (highly useful) to the actions 
> that we integrate (push, pull, update, commit, log, etc).
> I managed to figure out how to create an appropriate shell script 
> command line for using Mercurial with PHPEd, but the result is a crash 
> and error dump.  The EXACT SAME command in a windows command prompt 
> works perfectly fine.
> The error output is:
> c:\development\tortoisehg\hg.exe log --cwd 
> E:\projectscvs\beeza\includes\
> Traceback (most recent call last):   
> File "hg", line 29, in <module> 
> File "mercurial\util.pyc", line 992, in set_binary
> IOError: [Errno 9] Bad file descriptor
> I'm using the tortoisehg's hg.exe executable, but the same errors 
> (different line numbers) come up if I use the executables made by Lee 
> Cantey (
> Opening up cmd.exe and running:
> c:\development\tortoisehg\hg.exe log --cwd 
> E:\projectscvs\beeza\includes\
> Works perfectly.
> Any ideas what the problem might be and any possible work arounds?  I'm 
> unsure how PHPEd is executing the script, but I assume there must be 
> some environment variables missing or something.
> Any help would be GREATLY appreciated.

One of the first thing Mercurial does when invoked on Windows is to set
the binary attribute on STDIN, STDOUT, and STDERR file handles.  This is
required in order for commands that input/output text to work correctly
(import, export, diff, etc).

   msvcrt.setmode(fd.fileno(), os.O_BINARY)

The file handles provided by PHPEd do not care for this function call at
all.  I suspect we should be catching the IOError and ignoring it.

What do you think, Patrick?

Steve Borho (steve at
Key fingerprint = 2D08 E7CF B624 624C DE1F  E2E4 B0C2 5292 F2C6 2C8C

More information about the Mercurial mailing list