lostcable
4th December 2005 05:48 UTC
exec multi-arg command doesn't work??
If the user sets the checkbox on a component, then I want my installer to unzip a file.
The files and directories exist as follows:
C:\test\test_script.nsi
C:\test\install_dir
C:\test\install_dir\WINDOWS\unzip.exe
C:\test\install_dir\WINDOWS\myzipfile.zip
In my .nsi file, I have
SectionGroup /e "!Add-On Files" AddOnSection
!define SOURCE_DIR "install_dir"
Section "UnZip" UnzipSection
Exec '"${SOURCE_DIR}\WINDOWS\unzip.exe" ${SOURCE_DIR}\WINDOWS\myzipfile.zip -d $INSTDIR'
SectionEnd
; Additional sections not included for brevity
SectionGroupEnd
During install, the command window disappears as soon as it pops up. Therefore, I cannot read the error message. I also tried the batch file method but I got the same result.
I followed the NSIS user manual which instructs the use of quotes when executing a command with parameters. I searched this forum, googled all day for help, but came up empty.
As a sanity check, I have tried
Exec "${SOURCE_DIR}\WINDOWS\unzip.exe"
and that works fine.
Any help would be appreciated.
Takhir
4th December 2005 11:45 UTC
1. First of all I am not sure in your idea of ZIP usage - NSIS has possibilities for files decompression (both single exe and multi-file package). Lzma compression looks better then zip for me. And Windows Setup API includes ZIP decompression option "SetupDecompressOrCopyFile".
2. You can redirect process output to file using >file as last parameter.
3. SOURCE_PATH in your script defines relative path, this is why it might work for program start and failed as a parameter. Full path or
SetOutPath "$EXEDIR"
Exec '"${SOURCE_DIR}\WINDOWS\unzip.exe" "${SOURCE_DIR}\WINDOWS\myzipfile.zip" -d "$INSTDIR"'
may help your script to work properly. Please note quotes in my sample - this si really good thing for DOS command lines if you want application to get correct parameters (argv, argc).
4. If you still want to use Exec command, you can also read code samples with COMSPEC env. var. (use forum search please), you can also find samples how to auto-close DOS window and to redirect output.
5. BTW DOS window during installation looks not-professional, and this is why 2 plug-ins exist upon the times: nsExec (included to NSIS distribution, it's Readme in Contrib submenu) and
ExecDos, both support output redirection.
lostcable
5th December 2005 20:45 UTC
Thanks Takhir! I am new to NSIS and appreciate your help.
1. How do I call a Windows Setup function from my .nsi file?
2. I followed proven instructions from another thread on this forum but for some reason, it didn't work for me. Here is what I have:
SetOutPath "$EXEDIR"
ExpandEnvStrings $1 %COMSPEC%
nsExec::Exec '"$1" /C "${SOURCE_DIR}\WINDOWS\unzip.exe" "${SOURCE_DIR}\WINDOWS\CYGWIN_INSTALL.zip" -d "$INSTDIR" > "$INSTDIR\install.log"' $0
Please help me figure out what is wrong with the above.
3. Yes, the added quotes fixed the problem.
4&5. Yes, I used nsExec::Exec and it looks professional now.
Takhir
6th December 2005 14:22 UTC
1. Win API functions are available using System plug-in (Readme included to distribution).
2. You can skip comspec /c when using nsExec (not tested)
nsExec::Exec '"${SOURCE_DIR}\WINDOWS\unzip.exe" "${SOURCE_DIR}\WINDOWS\CYGWIN_INSTALL.zip" -d "$INSTDIR" > "$INSTDIR\install.log"'
Good idea is to use full paths for executable and parameters.
lostcable
6th December 2005 16:41 UTC
Okay, I have switched to using full paths.
!define SOURCE_DIR "C:\Program Files\NSIS\Examples\Test\install_dir"
1. System::Call 'kernel32::SetupDecompressOrCopyFile("${SOURCE_DIR}\WINDOWS\CYGWIN_INSTALL.zip", "$INSTDIR\CYGWIN_INSTALL.zip", FILE_COMPRESSION_MSZIP)'
--It didn't copy the file.
2. nsExec::ExecToLog '"${SOURCE_DIR}\WINDOWS\unzip.exe" "${SOURCE_DIR}\WINDOWS\CYGWIN_INSTALL.zip" -d "$INSTDIR" > "$INSTDIR\install.log"'
--Removed comspec but it still doesn't work.
Takhir
6th December 2005 17:40 UTC
OK, I tested and this works on my comp:
!define APP_NAME "wz_test"
Name "${APP_NAME}"
OutFile "${APP_NAME}.exe"
Section "Dummy Section" SecDummy
ExecDos::exec '"$EXEDIR\wzunzip.exe" -o nas.zip "$EXEDIR\out\"'
Pop $0
MessageBox MB_OK "$0"
SectionEnd
You can use nsExec in the same manner.