I am trying to run the windows helpfile compiler (hhc.exe
) from a script, but it shows very unexpected behaviour.
When I run it from cmd.exe with hhc pathtohelpproject.hpp
, the helpfile is compiled as expected. However, invoking the exact same command from python with the same working directory result in the program returning 0 and no output.
But it gets even more bizarre: I've created a batch file runhhc.bat
:
hhc "pathtohelpproject.hpp"
which I ran from the python script by invoking call runhhc.bat
, start runhhc.bat
and just runhhc.bat
.
All of them resulted in the same behaviour. However, with start runhhc.bat
the cmd instance was still open after hhc returned, so I tried entering the command manually again, without success. But when I entered the command in a freshly, manually opened cmd, it also didn't work! In fact, it only started working once I closed the cmd opened by my script.
What could be the explanation for this bizarre behaviour? And how can I run the compiler from a script regardless?
It's totally down to hhc.exe, nothing else. The trick is to look at the %ERRORLEVEL% after it runs. It returns "1" despite success. This could be used in a custom command to warn the user it's spurious, if the hhc.exe run is isolated from other stuff. HHC.exe is using HHA.dll. About HHA.dll info has not been published. Microsoft grant the HHA interface information under non-disclosure agreement (NDA) to approved help ISV's.
To go around this and continue you need to add
if not %errorlevel% 1 exit /B 1
in a batch file.And a python script calling this batch:
You may be interested in calling a CHM from a python script: