Recently I have been doing a fair amount of work trying to automate parts of the development process, in particular the version control aspects. I ran into what appeared to be limitations in the length of parameters accepted by the Clarion templates #RUN statement. Searching the newsgroups there were a few comments from people having similar issues and the symptoms were seemed a little sporadic. I decided that the safest way was to write the commands out to a temporary batch file and use #RUN to just call that.
This works great and has the added advantage of being able to execute, obviously, batches of commands in one go. The thing that is annoying about this is that you will get the command window popping up when the command is run. Often this is fine, especially for long tasks where it is nice to see the progress but sometimes it is annoying and it would to be nice to be able to hide the window.
There are a few ways to do this but essentially they all seem to revolve around the CreateProcess api Function.
- Write a helper DLL that wraps the CreateProcess function and can be easily called by the templates.
- Find something that already does this so I don’t have to.
If you want to go for option 1 in clarion you might like to look into PowerRun from Berthume Software which is available for free download. And of course you can dig right in and make the function call directly. However, if there is something suitable around I much prefer to use that.
After a quick search I found these two options:
- CHP.EXE (Create Hidden Process) – http://www.commandline.co.uk/chp/
- hidden Start (hstart.exe) – http://www.ntwind.com/software/utilities/hstart.html
I tried CHP first and it certainly does what it says it will but I found I wanted the option to wait until the spawned task was finished. In comes hstart. Hstart is pretty awesome. Lots of options and it also, funnily enough, does what it says it will…
For anyone interested, this is the template code I ended up with for calling hidden commands in a clarion template:
#GROUP(%RunCommandHidden, %Command, %TestMode=%FALSE),AUTO
#! We need to write the command out to a batch file for execution because
#! the #RUN command seems to have issues with the length of the command!
#SET(%BatchFileName, FullName(%BatchFileName, 2))
#! Now we call the batch file for execution
#! using cph.exe for "Create Hidden Process"
#RUN('hstart.exe /NOCONSOLE /WAIT ' & %BatchFileName),WAIT
#RUN('hstart.exe /WAIT ' & %BatchFileName),WAIT