ExecDos plug-in: Difference between revisions
m (ExecDos moved to ExecDos plug-in) |
m (conda execute links) |
||
(18 intermediate revisions by 9 users not shown) | |||
Line 5: | Line 5: | ||
<attach>ExecDos.zip</attach><br> | <attach>ExecDos.zip</attach><br> | ||
[http://forums.winamp.com/showthread.php?threadid=181442 Forum thread] | [http://forums.winamp.com/showthread.php?threadid=181442 Forum thread] | ||
Run with <code>conda execute</code> or install with <code>conda install</code> (see [[Conda]]). | |||
== Description == | == Description == | ||
Plug-in works with console applications - creates hidden child process with redirected i/o. | Plug-in works with console applications - creates hidden child process with redirected i/o. Compared to nsExec, ExecDos has four add-ons: | ||
# string parameter that serves as stdin for running application - may be useful if you want to give login/password to running application; | # string parameter that serves as stdin for running application - may be useful if you want to give login/password to running application; | ||
# sync/async (background) process launch option - async is good for long running applications; | # sync/async (background) process launch option - async is good for long running applications; | ||
# it works out of section - for .onInit check outs; | # it works out of section - for .onInit check outs; | ||
# multithreading - allows to run few applications at the same time. | # multithreading - allows to run a few applications at the same time. | ||
Plug-in | Plug-in can put application output to log file, 'detailed' installer window, any other text window, to installer stack or calls script function to handle every line. Maximum input (stdin) string size (i.e. plug-in second parameter) is up to 8 kB in the special NSIS build, 1 kB otherwise. The same with output lines length if target is not a file.<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. | ||
ExecDos is licensed under the same license as NSIS; ZLIB. [http://forums.winamp.com/showthread.php?postid=2488873#post2488873] | |||
== Syntax == | == Syntax == | ||
=== "exec" | === "exec" function === | ||
<highlight-nsis> | <highlight-nsis> | ||
ExecDos::exec [/NOUNLOAD /ASYNC] [ | ExecDos::exec [/NOUNLOAD /ASYNC] [/TOSTACK | /DETAILED | /TOWINDOW | /TOFUNC | /DISABLEFSR] [/TIMEOUT=xxx] \ | ||
[/ENDFUNC=func] application_to_run [stdin_string] [log_file_name | window | function] | |||
</highlight-nsis> | </highlight-nsis> | ||
: Executes console application. | : Executes console application. | ||
; ASYNC | ; ASYNC | ||
: | : does not wait for process to exit. Use 'wait' call if you want to get exit code. (/NOUNLOAD is mandatory!) | ||
; TIMEOUT | ; TIMEOUT | ||
: TOTAL execution time, milliseconds, for example /TIMEOUT=10000. Default is big enough. Short timeouts may cause app to | : TOTAL execution time, milliseconds, for example /TIMEOUT=10000. Default is big enough. Short timeouts may cause app to be terminated. | ||
; TOSTACK | |||
be | : pushes output to stack instead of log_file (do not use log_file_name parameter with this option). May be confusing if few apps puts lines to stack in the async mode. | ||
; DETAILED | |||
: puts output to installer DetailedView window. | |||
; TOWINDOW | |||
: adds output lines to target window. Edit, RichEdit, ListView and ListBox supported | |||
; TOFUNC | |||
: pushes output lines to installer stack and calls script function | |||
; DISABLEFSR | |||
: Added /DISABLEFSR switch to disable WOW64 file system redirection on Windows x64 for the internal ExecDos thread | |||
; application_to_run | ; application_to_run | ||
: application to run. | : application to run. | ||
Line 35: | Line 46: | ||
; 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) | ||
; window | |||
: output window handle | |||
; function | |||
: script function pointer | |||
=== "wait" | === "wait" function === | ||
<highlight-nsis>ExecDos::wait handle</highlight-nsis> | <highlight-nsis>ExecDos::wait handle</highlight-nsis> | ||
: Waits for process exit. | : Waits for process exit. | ||
; handle | ; handle | ||
: Control thread handle returned by 'exec' call in the /ASYNC mode. | : Control thread handle returned by 'exec' call in the /ASYNC mode. | ||
=== "isdone" function === | |||
<highlight-nsis>ExecDos::isdone /NOUNLOAD handle</highlight-nsis> | |||
: checks thread is running. Returns 1 if application have exited, 0 if still running, -1 on error. /ASYNC mode only. | |||
; handle | |||
: Control thread handle returned by 'exec' call. | |||
== Example == | == Example == | ||
Line 60: | Line 81: | ||
</highlight-nsis> | </highlight-nsis> | ||
''' | '''/TOSTACK''' | ||
<highlight-nsis> | |||
Push "ExecDos::End" # Add a marker for the loop to test for. | |||
ExecDos::exec /NOUNLOAD /TOSTACK "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log" | |||
Pop $0 # return value | |||
StrCmp $0 0 0 Failed | |||
## Loop through stack. | |||
Loop: | |||
Pop $1 | |||
StrCmp $1 "ExecDos::End" ExitLoop | |||
DetailPrint $1 | |||
Goto Loop | |||
ExitLoop: | |||
Return # Exit Function / Section | |||
Failed: | |||
MessageBox MB_OK "Exit code $0" | |||
Return # Exit Function / Section | |||
</highlight-nsis> | |||
'''/TOFUNC''' | |||
<highlight-nsis> | |||
Function OutputToLog | |||
#Log the Output into the nsis logfile | |||
LogText "$0" | |||
Pop $0 | |||
FunctionEnd | |||
Section -Core SEC0000 | |||
LogSet on | |||
#Get the Address of the function | |||
GetFunctionAddress $R2 OutputToLog | |||
#Install Service | |||
ExecDos::exec /TOFUNC '"$WINDIR\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe" "$INSTDIR\Core.exe"' '' $R2 | |||
SectionEnd | |||
</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 | ||
Line 70: | Line 124: | ||
cls | cls | ||
</pre> | </pre> | ||
'''Telnet and ssh''' Plug-in | '''Telnet and ssh''' Plug-in doesn't work with applications requiring terminal emulation. | ||
/TOFUNC option and isdone function added by Afrow UK | |||
[[Category:Plugins]] | [[Category:Plugins]] |
Latest revision as of 18:10, 30 October 2015
Author: Takhir (talk, contrib) |
Links
Download:
ExecDos.zip (40 KB)
Forum thread
Run with conda execute
or install with conda install
(see Conda).
Description
Plug-in works with console applications - creates hidden child process with redirected i/o. Compared to nsExec, ExecDos has four add-ons:
- string parameter that serves as stdin for running application - may be useful if you want to give login/password to running application;
- sync/async (background) process launch option - async is good for long running applications;
- it works out of section - for .onInit check outs;
- multithreading - allows to run a few applications at the same time.
Plug-in can put application output to log file, 'detailed' installer window, any other text window, to installer stack or calls script function to handle every line. Maximum input (stdin) string size (i.e. plug-in second parameter) is up to 8 kB in the special NSIS build, 1 kB otherwise. The same with output lines length if target is not a file.
'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.
ExecDos is licensed under the same license as NSIS; ZLIB. [1]
Syntax
"exec" function
ExecDos::exec [/NOUNLOAD /ASYNC] [/TOSTACK | /DETAILED | /TOWINDOW | /TOFUNC | /DISABLEFSR] [/TIMEOUT=xxx] \ [/ENDFUNC=func] application_to_run [stdin_string] [log_file_name | window | function]
- Executes console application.
- ASYNC
- does not wait for process to 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.
- TOSTACK
- pushes output to stack instead of log_file (do not use log_file_name parameter with this option). May be confusing if few apps puts lines to stack in the async mode.
- DETAILED
- puts output to installer DetailedView window.
- TOWINDOW
- adds output lines to target window. Edit, RichEdit, ListView and ListBox supported
- TOFUNC
- pushes output lines to installer stack and calls script function
- DISABLEFSR
- Added /DISABLEFSR switch to disable WOW64 file system redirection on Windows x64 for the internal ExecDos thread
- 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)
- window
- output window handle
- function
- script function pointer
"wait" function
ExecDos::wait handle
- Waits for process exit.
- handle
- Control thread handle returned by 'exec' call in the /ASYNC mode.
"isdone" function
ExecDos::isdone /NOUNLOAD handle
- checks thread is running. Returns 1 if application have exited, 0 if still running, -1 on error. /ASYNC mode only.
- handle
- Control thread handle returned by 'exec' call.
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" 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"
/TOSTACK
Push "ExecDos::End" # Add a marker for the loop to test for. ExecDos::exec /NOUNLOAD /TOSTACK "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execdos.log" Pop $0 # return value StrCmp $0 0 0 Failed ## Loop through stack. Loop: Pop $1 StrCmp $1 "ExecDos::End" ExitLoop DetailPrint $1 Goto Loop ExitLoop: Return # Exit Function / Section Failed: MessageBox MB_OK "Exit code $0" Return # Exit Function / Section
/TOFUNC
Function OutputToLog #Log the Output into the nsis logfile LogText "$0" Pop $0 FunctionEnd Section -Core SEC0000 LogSet on #Get the Address of the function GetFunctionAddress $R2 OutputToLog #Install Service ExecDos::exec /TOFUNC '"$WINDIR\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe" "$INSTDIR\Core.exe"' '' $R2 SectionEnd
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 doesn't work with applications requiring terminal emulation.
/TOFUNC option and isdone function added by Afrow UK