rajiv naravane
17th September 2006 18:44 UTC
nsExec
Documentation says :
nsExec will execute command-line based programs and capture the output without opening a dos box.
This is really a nice feature.
Question is, does it behave like ExecWait and waits till the program terminates or there is error executing the program?
Do I need to specify any timeout option to make it behave like ExecWait()
Thanks
kichik
22nd September 2006 10:05 UTC
Yes, it waits.
rajiv naravane
22nd September 2006 14:47 UTC
Thanks, Kichik. A follow up question: As part of the installation, I need to stop, remove, uninstall and reinstall one or more Windows services on Windows 2000 and Windows 2003 server platforms.
Currently I am using ExecWait 'net start' etc. If the service can not be stopped (and it could happens in production environment) and goes into error state, is ExecWait() going to hang? Would nsExec with timeout parameters be a better option? With nsExec I can retry and eventually pop up a dialog box indicating error -- What do you think?
I have seen some plugins as well which use C APIs to talk to ServiceControl manager? Is this approach any better than 'net start' etc commands when it comes to handling errors -- That's the most important thing for me.
Thanks for your help.
kichik
22nd September 2006 14:53 UTC
The plug-ins are built especially for handling services, so I'd imagine they have better error handling then ExecWait or nsExec for this specific case. Besides, using API is always better than a command line utility which may not have the same interface in future versions, on different languages or might not even exist in older versions of Windows.
rajiv naravane
22nd September 2006 14:57 UTC
Would ExecWait() hang, though or it recovers gracefully? Thanks.
kichik
22nd September 2006 14:58 UTC
It'll wait until the process it executed returns. If the process hangs, it'll hang.
rajiv naravane
22nd September 2006 15:02 UTC
I guess then, I have two choices to recover gracefully from errors:
Use nsExec with timeout, parse its output and retry or show error dialog.
Go for the plugin approach.