ExecCmd plug-in: Difference between revisions
No edit summary |
No edit summary |
||
Line 26: | Line 26: | ||
=== "wait" DLL function === | === "wait" DLL function === | ||
<highlight-nsis> | <highlight-nsis>ExecCmd::wait handle</highlight-nsis> | ||
: Waits for process exit. | : Waits for process exit. | ||
; handle | ; handle |
Revision as of 12:25, 24 January 2006
Author: Takhir (talk, contrib) |
Links
Download:
ExecCmd.zip (10 KB)
Forum thread
Description
Plug-in works with console applications - creates hidden child process and sends stdin string to console window using WM_CHAR messages. Plug-in has sync and async (background) process launch option - async is good for long running applications and for few applications running at the same time. It works out of section - for .onInit check outs. Maximum input (stdin) string size (i.e. plug-in second parameter) is up to 8kB in the special NSIS build, 1 kB otherwise.
'exec' return code depends on the execution mode: application exit code for sync mode and control thread handle for async one. Handle required for 'wait' - it helps to understand what application exit to wait for. If stack is not used between 'exec' and 'wait', both Pop after 'exec' and 'wait' parameter may be skipped - handle just sits in the stack.
Syntax
"exec" DLL function
ExecCmd::exec [/NOUNLOAD /ASYNC] [/TIMEOUT=xxx] application_to_run stdin_string
- Executes console application.
- ASYNC
- Not waits for process exit. Use 'wait' call if you want to get exit code. (/NOUNLOAD is mandatory!)
- TIMEOUT
- TOTAL execution time, milliseconds, for example /TIMEOUT=10000. Default is big enough. Short timeouts may cause app to be terminated.
- application_to_run
- application to run.
- stdin_string
- all that application can get from stdin
"wait" DLL function
ExecCmd::wait handle
- Waits for process exit.
- handle
- Control thread handle returned by 'exec' call in the /ASYNC mode.
Example
Async execution with stdout to file:
ReadEnvStr $0 "ComSpec" ExecCmd::exec /NOUNLOAD /ASYNC /TIMEOUT=2000 \ '$0 /C "$EXEDIR\consApp.exe" >ExecCmd.log' "test_login$\r$\ntest_pwd$\r$\n" Pop $0 # thread handle for wait # you can add some installation code here to execute while application is running. ExecCmd::wait $0 Pop $0 # return value MessageBox MB_OK "Exit code $0"
Sync execution:
ExecCmd::exec /TIMEOUT=2000 '"$EXEDIR\consApp.exe"' "test_login$\r$\ntest_pwd$\r$\n" Pop $0 ; return value - process exit code or error or STILL_ACTIVE (0x103). MessageBox MB_OK "Exit code $0"
BAT files specifics. On some of Win98 systems where "Close on exit" option is not set for DOS apps it was found
that after batch execution was finished (and installer continue it's job) hidden window still remains in the system
as "winoldapp". Following two lines solve the problem
@echo off # place your code here cls