Help+Manual's command line interface uses the Command Prompt (cmd.exe, also referred to as CMD) language, so it will not work directly in PowerShell, which is a different Windows shell language. However, it is quite possible to call CMD in PowerShell scripts. The following method was posted on the Help+Manual user forum by Help+Manual user Julio, who we'd like to thank here for this great contribution.
See H+M command line syntax for details of the syntax, which remains the same within the command line created for Help+Manual.
How to use the Help+Manual Command Prompt API in PowerShell
The key to making this work is to use ProcessStartInfo and Process objects. If you use the Start-Process command you can't control the termination your process, which is acquired by using the -Wait parameter. What happens is that the system does not really wait for the process to finish before starting another one. This leads to conflicts if you want to compile outputs with separate command prompts, because Start-Process triggers all processes at once. They then all fail because they try to call Help+Manual to publish all versions at the same time.
$processInfo = New-Object System.Diagnostics.ProcessStartInfo
$processInfo.FileName = "cmd.exe"
$processInfo.Arguments = '/c ""C:\Program Files (x86)\EC Software\HelpAndManualX\HELPMAN.EXE" "E:\Documents\My HelpAndManual Projects\Demo\NewProjectHM9.hmxp" /CHM="NewProjectHM9.chm" /I="CHM" /L="project.log""'
$processCHM = New-Object System.Diagnostics.Process
$processCHM.StartInfo = $processInfo
[void]$processCHM.Start()
$processCHM.WaitForExit()
switch ($processCHM.ExitCode) {
0 {
Write-Host "CHM compiled successfully. No errors."
}
1 {
Write-Host "Error: General critical error. Compilation could not be finished and was aborted."
}
2 {
Write-Host "Warning: One or more warnings occurred. See the log file or console output for details."
}
3 {
Write-Host "Error: One or more non-critical errors occurred. See the log file or console output for details."
}
default {
Write-Host "Error: Help+Manual returned an unexpected exit code: $($processCHM.ExitCode)"
}
}
The individual commands
•The $processInfo statements create a ProcessStartInfo object for the CMD program, along with the entire command line for publishing your project with Help+Manual.
•The $processCHM statements execute the command line with a functional wait function.
•The switch loop at the end ensures that you always have a meaningful description of the exit code provided by Help+Manual. This is useful if you are compiling manually from the command line and including a log file with Help+Manual's /L switch, because this disables the console messages.
IMPORTANT: Quoting and double-quoting the arguments
All the arguments must be quoted, and the $processInfo.Arguments must be double double quoted. That is not a typo! The entire argument list must be quoted, so here you use single quotes. Then the /c parameter for the CMD Command Prompt program has its own string of arguments, which is the Help+Manual command line. This must be an additional single string between double quotes. And the individual arguments within this string must also be double-quoted.
Entire arguments string: |
'/c ... ' |
Argument string for /c: |
'/c "..." ' |
Arguments of /c: |
'/c ""HELPMAN.EXE" "project.hmxp" /CHM="NewProjectHM9.chm" /I="CHM" /L="project.log""' |