ExecCmd plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:


== Links ==
== Links ==
<p>'''''This plug-in is no longer updated and has been superseded by the [[ExecDos plug-in]].'''''</p>
Download:<br>
Download:<br>
<attach>ExecCmd.zip</attach><br>
<attach>ExecCmd.zip</attach><br>
Line 18: Line 19:
: 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!)
: Does not wait for process exit. Use 'wait' call if you want to get exit code. (/NOUNLOAD is mandatory!)
; TEST
; TEST
: Console window is visible with this key.
: Console window is visible with this key.
Line 24: Line 25:
: 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. Further " after the executable are not allowed. Use EcexDos instead.
: application to run. Further " after the executable are not allowed. Use ExecDos instead.
; stdin_string
; stdin_string
: all that application can get from stdin
: all that application can get from stdin

Latest revision as of 09:46, 18 July 2013

Author: Takhir (talk, contrib)


Links

This plug-in is no longer updated and has been superseded by the ExecDos plug-in.

Download:
ExecCmd.zip (10 KB)
Forum thread

Description

Plug-in works with console applications - creates hidden child process with stdin from file (<stdin.txt) or sends stdin string to console window using WM_CHAR messages. Second method is more secure (for passwords) but does not work on Win98 and earlier systems. On Win98 exit code (Pop value) may be not correct as well. 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
Does not wait 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. Further " after the executable are not allowed. Use ExecDos instead.
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"

" after the executable are not allowed. Use EcexDos instead:

;Does not work (in /TEST mode a console window will pop up but the file will not be executed):
ExecCmd::exec '"7za.exe" x "file.7z"'
 
;Does work:
ExecCmd::exec '"7za.exe" x file.7z'

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