- NSIS Discussion
- dosExecute plugin
Archive: dosExecute plugin
Takhir
28th May 2004 10:46 UTC
dosExecute plugin
2 parameters - program to start and string to use as stdin for program. Plugin creates child process with redirected i/o (pipes). Works in debug mode now - few Windows popup message boxes appears and console application window is visible - I'll change mode to SH_HIDE and remove messages in next version. Please note following string in execDos.nsi file (see attachment):
execDos::execDos "c:\consApp.exe" "test_login$\ntest_pwd$\n"
Test console appl. included - it printfs header and requests for login and password, then exits. Put it to C:\ for tests or change path in first parameter. Plugin also returns program exit code to stack (if finished, waits max 1 sec, probably something like .r0 required to get it, I am not sure :). This may not works with Windows telnet or ftp clients, but with simple console application it was OK.
http://nsis.sourceforge.net/ExecDos_plug-in
Takhir
31st May 2004 07:47 UTC
Project and binaries
Plugin takes 2 strings from stack (application name and stdin text), creates hidden child process with redirected I/O, writes input string parameter to redirected stdin (pipe buffering works fine) and catches stdout. Returns to stack application' exit code.
Project and binaries attached. To test plugin with you application, change file/path and input string parameter in dosExec.nsi, put dosExec.dll to NSIS\Plugin folder and recompile dosExec.nsi script. Run dosExec.exe (uninstall not required). Sample DOS application included – requests for login and password, then exits, you can see how this works if run app. from console window. To use it for plugin test, put consApp.exe to c:\ or change path in script.
Build with MS Visual Studio 6, SP 5. Tested on W98 SE – W2K server.
Please note correct dll and entry point names
dosExec::dosExec "c:\consApp.exe" "test_login$\ntest_pwd$\n"
Takhir
12th January 2005 19:10 UTC
Few versions were published in related threads, but it will be better to continue here :) Wording and design was improved in current version.
Finally this plug-in based on the same system calls as nsExec, but you can also give 'stdin' string (up to 1024 chars) to running application. In most cases this will be authorization login/password pair.
For example:
execDos::exec "$EXEDIR\consApp.exe" "test_login$\ntest_pwd$\n" "$EXEDIR\execDos.log"
consApp.exe included for test purposes, it sleeps(1 sec) before exit(5), so plug-in text on the top of INSTFILES page becomes visible.
Takhir
16th January 2005 15:04 UTC
Updated to support long strings - now plug-in allocates string buffers according to incoming string_size parameter. This may be 8k for special NSIS build (1024 otherwise). I guess this is also stack string size.
bdfy
8th February 2005 11:17 UTC
Takhir
OK, it works , but just like this NSIS standart command...
ExecShell '"$INSTDIR\Res\Campaigns\pbtl.exe" -u resistance.pbo' SW_HIDE
For example
execDos::exec '"$INSTDIR\Res\Campaigns\pbtl.exe" -u resistance.pbo'
doesn't match for my script , because I need actions to be sequenced, step-by-step. I have to wait while DOS operation ends. Can you help me ?
I can easily make it in Inno and IMHO NSIS must have this feature.
Takhir
8th February 2005 11:48 UTC
Plug-in waits application to close it's stdout (all done), after this waits for exit_code_process (up to 2 sec) and exits after this only. This is "wait" mode I guess. So once again - is pbtl.exe DOS or "windowed" application? In the last case DOS plug-ins is a wrong way.
bdfy
8th February 2005 12:25 UTC
pbtl.exe is DOS-applicattion and it works about 10 sec in my installer.
Takhir
9th February 2005 14:19 UTC
During email conversation it was found that the main problem is bad plug-in manual (NSIS tradition :) ) So I'd like to explain details:
1. Only command_line parameter is mandatory, other parameters (timeout, stdin_string and log_file_name) are optional, may by skipped or ""
execDos::exec command_line [/TIMEOUT=xxx] [stdin_string] [log_file_name]
for example
execDos::exec "$INSTDIR\my_app.exe"
(while stdin_string was main idea of this plug-in – user input emulation)
2. "$EXEDIR\${APP_NAME}.log" log file name in the included script sample require "!define APP_NAME execDos" or something like this (see execDos.nsi )
3. Be very careful with bat files - it's DOS window autoclose mode depends on the user's system settings ("Close On Exit" property), I could reproduce situation with installer hanging. nsExec supports /TIMEOUT parameter, while error "timeout" in such situations may looks like "unsuccessful". May be it is possible to change autoclose parameter for the time when plug-in is running? "cmd.exe /C" works on XP/2K only. Good news - this still works fine with direct call to DOS application (without bat file) ;) .
I added timeout option to ExecDos plug-in, mainly for possible batch file problems, attached.
bdfy
9th February 2005 19:15 UTC
Takhir
The problem isn't solved...:( check your mail.
Anders
9th February 2005 20:44 UTC
as far is i know, this bat file will autoclose on all systems:
@echo off
echo hello world
cls
bdfy
9th February 2005 23:10 UTC
Anders
the problem is not to close...
the problem is to hide DOS screen while bat file in progress...
Takhir
10th February 2005 07:42 UTC
This is not plug-in problem :)
I took bdfy script and did following:
1. Carefully replaced ExecWait calls with ExecDos. After this all black screens dissapeared.
2. Added MessageBoxes showing application exit codes.
3. According to exit codes found and fixed suspicious places in the original code, like this - program extracts file to current SetOutPath dir, but tries to start program from another one
SetOutPath "$INSTDIR\resistance"
File "Files\bat\Resdelete.bat"
ExecWait "$INSTDIR\Resdelete.bat"
Now exit codes of 3 runs are 0, 1 and 1; resistance.pbo file size changed, looks working. Full script sent by email.
2 Anders: XP&2K - no problem, but on Win98 it's a real head pain... In my tests hidden Winoldapps on Win98 remain in Ctrl-Alt-Del list and create problem on next reboot :(
bdfy
10th February 2005 14:51 UTC
Takhir
Thank you very much (ñ):)
All problems are solved , everything works fine - 10x to Takhir.:beer:
Takhir
10th February 2005 15:21 UTC
Sorry, Anders, I re-tested on Win98 and found that your code works! No Oldapps in the tasks list. I searched google but not found this decision.. Thanks :)
bdfy: do not forget to add 'echo off + cls' to your bat files. Application's output still appears in the log file (if set).
Guillaume.L
17th July 2005 02:12 UTC
How do I install your plugin?
Takhir
17th July 2005 06:52 UTC
1. Download the package http://forums.winamp.com/attachment....postid=1587794 (attached to the post above).
2. Put ExecDos.dll from zip to Program Files\NSIS\Plugins folder on your comp
3. Read included to zip execdos.nsi for usage sample. The simplest command line (no log file and stdin string):
execDos::exec "path\file" "" ""
Pop $0
Takhir
17th July 2005 10:57 UTC
Updated wiki page
Guillaume.L
18th July 2005 22:11 UTC
Is there a way not to make it hide the dos window if there is one?
Takhir
19th July 2005 06:45 UTC
Use ExecWait NSIS Instruction (Documentation, 4.9.1.4).
Takhir
26th July 2005 08:41 UTC
New options (wiki page):
/ASYNC - async application execution. Not waits for process exit, returns control to installer immediately after process launch. New optional 'wait' function to get application exit code (if required). Multithreading worked in my tests, so few DOS application can work at the same time ('exec' returns handle for access to particular process in 'wait' call)
/BRAND - branding text instead of "ExecDos plug-in: exe_name"
DarkAvenger
13th June 2006 19:19 UTC
Hi Takhir,
is it possible to add an option to start the program as diferent user - pass username and password of new user as parameters. Something like RunAs dll but incorporated in ExecDos.
Thaks in advanced
Takhir
14th June 2006 18:18 UTC
It is possible, but most of used API calls marked in MSDN as NT (XP?) compatible only, so we can lose Win9x this case.
DarkAvenger
14th June 2006 19:27 UTC
Takhir,
thank you for your fast reply... Windows NT/2000/XP/2k3/Vista is ok with me... You can add a new function to the dll with run as functionality without lose existing one that support 9x OS.
Looking forward for the new version of ExecDos with RunAs ...
Thanks in advanced
dmccordjr
22nd June 2006 17:45 UTC
Feature Request: Allow a value for no Timeout
Please, I humbly :) request you to Permit a "No" Timeout value for /TIMEOUT or a flag for example
/TIMEOUT=-1 or /NOTIMEOUT Whatever works best for you.
I would like to use this command to Launch Applications. Mainly Java Applications. The Applications Run Indefinitely.
So I need a way to Turn off the time out. The man reason I want to use your tool is the Log to file and the Async.
We tend to use NSIS as a Compiled Batch File for little utilities.
Takhir
22nd June 2006 19:31 UTC
If not set, timeout is 0xffffff ms = 4 hours. You can define it as 0xffffffff this will be 256 times more. Is this enough?
dmccordjr
22nd June 2006 20:29 UTC
Takir
Wow, :D well that's 42 days, approximately. LOL! That will work. Not quite the same a never. But definitely long enough, I certainly hope our users open and close the app at least once in 1024 hours.
Thanx for the quick response.
Takhir
23rd June 2006 06:40 UTC
May be you need no-wait application launch, this case use ExecShell (NSIS command) or WinExec (via System plug-in). Both support SW_HIDE parameter and not waits a process exit (and allows installer to finish).
Clammerz
11th December 2006 14:15 UTC
Sorry if I'm bumping the wrong thread, but this was the thread linked to on the Wiki page.
How do you utilize the /TOSTACK option?
The Wiki page is kinda poorly documented on this feature.
Takhir
11th December 2006 15:15 UTC
Plug-in pushes to stack as many (not empty) lines as it gets from app's stdout basing on '\n' delimiter (\r char just skipped). Long lines will be truncated on the NSIS line limit (1024-1 for common build). If log defined data go to file as well.
Clammerz
11th December 2006 16:39 UTC
Oh, thank you.
I was hoping it would work somewhat similar to a 'live output' that the logfile option does.
Would make it easier to handle live output internally by NSIS rather than reading from the logfile.
I was wondering... Since you have already successfully redirected live output to a logfile, is it possible for you to redirect it to the details box?
I have a external application that needs to run during install. It outputs it's progress as dots:
"............" and so on, untill it reaches:
".............................. DONE."
ExecToLog is unable to do it. It was discussed allot in this thread:
http://forums.winamp.com/showthread....hreadid=126972
But no solution was found.
If it can't be done, I guess I can resort to /ASYNC, and have a loop reading from the file every 1/2 a second or so..
Thanks for your help thus far.
Takhir
11th December 2006 18:56 UTC
It is possible, may be I'll add new option next weekend (or you can do this earlier ;) ).
/async should work for now.
Takhir
13th December 2006 10:00 UTC
I added /detailed option, while installer' Detailed window sync looks not very good with my test app - pauses and jumps when new items appear...
thetw
4th August 2009 00:02 UTC
Hello, I'm hoping this is the appropriate thread to ask this question...
I am in the process of converting to the unicode NSIS installer and I am using ExecDos. I had to change several other plugins to get it to work, but ExecDos seems to be okay. Can you tell me whether it is Unicode compliant or it is just lucky that no inputs have broken it yet? If it is not Unicode compliant, is there a recommended solution?
Thanks for your help!
Takhir
4th August 2009 18:09 UTC
Current version of ExecDos (July 2007) looks multibyte only. Unfortunately I have not NSIS Unicode installed now, so attached variant is 100% not tested. I just replaced char->TCHAR and added unicode release/debug configurations.
Just found - last string output /towindow and /tofinc may not work if it is not terminated with '\n' - require some code like this is done for /tostack :(. And one more - plug-in creates process using Unicode syscall, but I am not sure that catched output from CLI application (redirected to pipes) will be Unicode as well.
Have fun ;).
NsisUsernew
16th November 2009 09:20 UTC
Regarding ExecDos
hi all,
I am attaching a python executable with NSIS. The runtime prints of python's windows executable is needed to be outputed on the showdetails field of NSIS's Installation Page. We are using ExecDos dll, plugins to display runtime output of python's windows executable (hello.exe). The code snippet is as follows:
ExecDos::exec /NOUNLOAD /ASYNC /DETAILED /TIMEOUT=10000 "hello.exe"
Pop $0
ExecDos::wait $0
where hello.exe is window's executable of hello.py,
hello.py is:
import os, time, sys
import WConio
print "something is running ....."
sys.stdout.flush()
x = WConio.wherex()
y = WConio.wherey()
WConio.gotoxy(x+50,y-1)
time.sleep(10)
print "ok"
sys.stdout.flush()
"Console window" Output of above hello.exe is:
something is running ...... ok
But when hello exe is used in NSIS, the display looks like this:
something is running .......
ok
My intention is to get the print like as shown for Console window, ie 'ok' on the same line. Can anyone suggest what I am doing wrong? NOTE that when I use the ',' after the first print, the string is buffered even if I do a flush (as sys.stdout.flush()).
Takhir
17th November 2009 06:55 UTC
gotoxy() sounds like terminal command. First print() sends CR, but after this you move marker back to previous line. None of NSIS plug-ins supports terminal emulation.
NsisUsernew
18th November 2009 16:55 UTC
Reason of using gotoxy(), is to set the cursor position, as my intention is to print
Something is running........(sleep for 10, then print)..Ok
using below code:
print "Something is running.....",
sys.stdout.flush()
sys.sleep(10)
print "Ok"
sys.stdout.flush()
sys.stdout.flush(), is not working with "comma", it buffers "Something is running....." with "Ok" string and throw result on showdetails window after 10.
Can you suggest the way to make flush to work with ","?
Genjuro
17th March 2010 01:44 UTC
If the parameters of the program has "", what i do?
Takhir
17th March 2010 14:52 UTC
NSIS script allows both " and '. So 'notepad.exe "c:\path to file\file name.txt"' is possible.
Plainjay
28th July 2010 21:53 UTC
Exec Wait and Logging?
I'm trying to use ExecDos::wait with logging function.. does it not have the same option?
syntax I'm using ExecDos::wait "C:\program.exe" "" "$EXEDIR\test.log"
ExecWait worked fine but I don't think it'll log to a file like I want.
Also tried nsExec::ExecToLog but wasn't getting the result I'm looking for...
- NSIS Discussion
- dosExecute plugin
Archive: dosExecute plugin
Afrow UK
29th July 2010 10:34 UTC
Check the readme again. Tip: Use Exec not Wait.
Stu
Afrow UK
18th January 2011 17:57 UTC
I have uploaded a new version of the plug-in.
* Added Unicode build (just noticed there was already a Unicode build in this thread but never mind - this version has been tested at least).
* Uses new plug-in API (/NOUNLOAD not necessary with /ASYNC).
* Added /DISABLEFSR switch to disable WOW64 file system redirection on Windows x64 for the internal ExecDos thread (the old version would fail if the executable was in system32).
http://nsis.sourceforge.net/ExecDos_plug-in
Stu
HaMsTeYr
5th September 2012 21:22 UTC
Afrow, I noticed that the log files are encoded in UTF-8. Is there anyway to change that to UTF16-LE?
I'm writing a piece of code at the moment, and I'm trying to read Unicode characters into the stack, via an external file. I'm using the NSIS Unicode build at the moment.
I have tried executing to function instead of out to log, but it seems that only outputting it out to the log keeps the Unicode characters as they are.
I can think of only a few ways to do this, like a FileRead that works for UTF-8 (Using FileRead screws up the characters, and FileReadUTF16LE is no better.)
Another alternative is to stick of course, with FileReadUTF16LE, but the file has to be encoded in UTF-16 LE as well, if not it also becomes a garbled mess.
I know it may seem like asking for much, but would you happen to know any way around this?