ExecCmd plug-in: Difference between revisions
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
== Description == | == 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.<br> | 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.<br> | ||
'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. | '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.<br> | ||
Plug-in adds 'ComSpec' env. variable with /C key at the beginnig of the command line, this may additionally limit command line length. Current version was tested on XP - 2003. | |||
== Syntax == | == Syntax == | ||
=== "exec" DLL function === | === "exec" DLL function === | ||
<highlight-nsis> | <highlight-nsis> | ||
ExecCmd::exec [/NOUNLOAD /ASYNC] [/TIMEOUT=xxx] application_to_run stdin_string | ExecCmd::exec [/NOUNLOAD /ASYNC] [/TEST] [/TIMEOUT=xxx] application_to_run stdin_string | ||
</highlight-nsis> | </highlight-nsis> | ||
: Executes console application. | : Executes console application. | ||
; ASYNC | ; ASYNC | ||
: Not waits for process exit. Use 'wait' call if you want to get exit code. (/NOUNLOAD is mandatory!) | : Not waits for process exit. Use 'wait' call if you want to get exit code. (/NOUNLOAD is mandatory!) | ||
; TEST | |||
: Console window is visible with this key. | |||
; TIMEOUT | ; TIMEOUT | ||
: TOTAL execution time, milliseconds, for example /TIMEOUT=10000. Default is big enough. Short timeouts may cause app to be terminated. | : TOTAL execution time, milliseconds, for example /TIMEOUT=10000. Default is big enough. Short timeouts may cause app to be terminated. | ||
Line 34: | Line 37: | ||
Async execution with stdout to file: | Async execution with stdout to file: | ||
<highlight-nsis> | <highlight-nsis> | ||
ExecCmd::exec /NOUNLOAD /ASYNC /TIMEOUT=2000 \ | ExecCmd::exec /NOUNLOAD /ASYNC /TIMEOUT=2000 \ | ||
' | '"$EXEDIR\consApp.exe" >ExecCmd.log' "test_login$\r$\ntest_pwd$\r$\n" | ||
Pop $0 # thread handle for wait | Pop $0 # thread handle for wait | ||
# you can add some installation code here to execute while application is running. | # you can add some installation code here to execute while application is running. |
Revision as of 07:32, 25 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.
Plug-in adds 'ComSpec' env. variable with /C key at the beginnig of the command line, this may additionally limit command line length. Current version was tested on XP - 2003.
Syntax
"exec" DLL function
ExecCmd::exec [/NOUNLOAD /ASYNC] [/TEST] [/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!)
- TEST
- Console window is visible with this key.
- 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:
ExecCmd::exec /NOUNLOAD /ASYNC /TIMEOUT=2000 \ '"$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