ExecDos plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
Line 7: Line 7:


== Description ==
== Description ==
Plug-in works with console applications - creates hidden child process with redirected i/o. Compare to NSISdl has three add-ons: 1) string parameter that serves as stdin for running application; 2) sync/async (background) process launch option; 3) it works out of section. First may be useful if you want to give login/password to running application, second - for long running applications, third - for .onInit check -outs. Plug-in puts log to file (if valid file name defined in the command line) instead of 'detailed' installer window. Maximim input string size for application is 8kB in the special NSIS build, 1 kB otherwise.
Plug-in works with console applications - creates hidden child process with redirected i/o. Compare to NSISdl has four


== How To Use ==
add-ons:
1) string parameter that serves as stdin for running application - may be useful if you want to give login/password to
 
running application;
2) sync/async (background) process launch option - async is good for long running applications;
3) it works out of section - for .onInit check outs.
4) multithreading - allows to run few applications at the same time.
Plug-in puts log to file (if valid file name defined in the command line) instead of 'detailed' installer window. Maximim
 
input string size for application is 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 ===
<highlight-nsis>
<highlight-nsis>
ExecDos::exec [/NOUNLOAD /ASYNC] [/TIMEOUT=xxx] application_to_run [stdin_string] [log_file_name]
ExecDos::exec [/NOUNLOAD /ASYNC] ["/BRAND=Some text"] [/TIMEOUT=xxx] application_to_run [stdin_string] [log_file_name]
</highlight-nsis>
</highlight-nsis>
: Executes console application.
; ASYNC
; ASYNC
: Not waits for process exit. Use 'wait' call if you want to get exit code
: Not waits for process exit. Use 'wait' call if you want to get exit code
; BRAND
: Displays text above progress bar (default is "ExecDos plug-in: your_app_name.exe")
; 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.
; application_to_run
; application_to_run
: application to run.
: application to run.
Line 23: Line 45:
; log_file_name
; log_file_name
: file where to put app's stdout (optional, but use "" if stack is not empty)
: file where to put app's stdout (optional, but use "" if stack is not empty)
=== "wait" DLL function ===
<highlight-nsis>ExecDos::wait handle</highlight-nsis>
: Waits for process exit.
; handle
: Control thread handle returned by 'exec' call in the /ASYNC mode.


== Example ==
== Example ==
Sync execution:
<highlight-nsis>
<highlight-nsis>
ExecDos::exec /TIMEOUT=2000 "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log"
ExecDos::exec /TIMEOUT=2000 "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log"
Line 30: Line 59:
MessageBox MB_OK "Exit code $0"
MessageBox MB_OK "Exit code $0"
</highlight-nsis>
</highlight-nsis>
or
 
Async execution:
<highlight-nsis>
<highlight-nsis>
ExecDos::exec /NOUNLOAD /ASYNC "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log"
ExecDos::exec /NOUNLOAD /ASYNC "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log"
# place here some installation code or Sleep+DetailPrint
# place here some installation code or Sleep+DetailPrint
ExecDos::wait
Pop $0 # thread handle for wait
# you can add some installation code here to execute while application is running.
ExecDos::wait $0
Pop $0 # return value
Pop $0 # return value
MessageBox MB_OK "Exit code $0"
MessageBox MB_OK "Exit code $0"
</highlight-nsis>
</highlight-nsis>
or
 
<highlight-nsis>
'''BAT files specifics.''' On some of Win98 systems where "Close on exit" option is not set for DOS apps it was found  
ExecDos::exec "$EXEDIR\consApp.exe" "" ""
 
Pop $0 # return value
that after '''batch''' execution was finished (and installer continue it's job) hidden window still remains in the system  
MessageBox MB_OK "Exit code $0"
 
</highlight-nsis>
as "winoldapp". Following two lines solve the problem
'''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
<pre>
<pre>
@echo off
@echo off

Revision as of 06:29, 26 July 2005

Author: Takhir (talk, contrib)


Links

Download:
ExecDos.zip (40 KB)
Forum thread

Description

Plug-in works with console applications - creates hidden child process with redirected i/o. Compare to NSISdl has four

add-ons: 1) string parameter that serves as stdin for running application - may be useful if you want to give login/password to

running application; 2) sync/async (background) process launch option - async is good for long running applications; 3) it works out of section - for .onInit check outs. 4) multithreading - allows to run few applications at the same time. Plug-in puts log to file (if valid file name defined in the command line) instead of 'detailed' installer window. Maximim

input string size for application is 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

ExecDos::exec [/NOUNLOAD /ASYNC] ["/BRAND=Some text"] [/TIMEOUT=xxx] application_to_run [stdin_string] [log_file_name]
Executes console application.
ASYNC
Not waits for process exit. Use 'wait' call if you want to get exit code
BRAND
Displays text above progress bar (default is "ExecDos plug-in: your_app_name.exe")
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 (optional, use "" if stack is not empty)
log_file_name
file where to put app's stdout (optional, but use "" if stack is not empty)

"wait" DLL function

ExecDos::wait handle
Waits for process exit.
handle
Control thread handle returned by 'exec' call in the /ASYNC mode.

Example

Sync execution:

ExecDos::exec /TIMEOUT=2000 "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log"
Pop $0 # return value
MessageBox MB_OK "Exit code $0"

Async execution:

ExecDos::exec /NOUNLOAD /ASYNC "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log"
# place here some installation code or Sleep+DetailPrint
Pop $0 # thread handle for wait
# you can add some installation code here to execute while application is running.
ExecDos::wait $0
Pop $0 # return value
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

Telnet and ssh Plug-in not works with applications requiring terminal emulation.