Searching PATH for hg on windows

Stephen Darnell stephen at darnell.plus.com
Sun Apr 9 21:26:29 UTC 2006


Just a note for those Windows users who don't use hg.exe
I have multiple versions of hg and to invoke the right one I modify my 
PATH - but in order for this to work well for me I needed a more advanced 
hg.cmd wrapper:

@echo off
for /f %%i in ("hg") DO set HGSCRIPT="%%~$PATH:i"
if %HGSCRIPT% == "" (
  echo Cannot find hg on PATH
  exit /b 1
)
python %HGSCRIPT% %*

This searches PATH for a file called 'hg' (no extension) and invokes it 
explicitly with the python interpreter.
This avoids the Windows redirection bug when invoking .py files, and fixes 
an exit code problem I had been seeing on XP too.

I've updated the wiki page: 
http://www.selenic.com/mercurial/wiki/index.cgi/WindowsInstall

Another possible solution for better behaviour on Windows might be to 
install a hg.cmd along side the hg (python) wrapper. This hg.cmd could 
determine it's own directory and invoke the python wrapper from there with:
 @python "%~p0\hg" %*

Any preference?  Would there be a problem installing this file on all 
platforms, or can the installer indicate that it is only installed on 
Windows?

Regards,
 Stephen




More information about the Mercurial mailing list