Reputation: 1896
I wrote following commands in .bat
file which works for me quite well. Now I am trying to write a NSIS
based graphical installer and need to reproduce the same with NSIS
. I do not understand how I can get this done.
set PATH=%PATH%;C:\RailsInstaller\Ruby2.1.0\bin
set RAILS_ENV=production
cd C:\myapp
bundle install --local
I would like to know how to write a nsi
script which would be equivalent to the above commands being run in shell one after another.
Upvotes: 2
Views: 2225
Reputation: 101764
You need to be a little careful when updating %PATH% in NSIS because the NSIS string length limit is shorter than the %PATH% length limit. You can work around this by calling the Windows API directly:
!define ERROR_ENVVAR_NOT_FOUND 203
!if "${NSIS_PTR_SIZE}" <= 4
!include LogicLib.nsh
Function ProcessEnvAppendPath ; IN:Path OUT:N/A
System::Store S
Pop $1
System::Call 'KERNEL32::GetEnvironmentVariable(t "PATH", t, i0)i.r0'
${If} $0 = 0
System::Call 'KERNEL32::SetEnvironmentVariable(t "PATH", tr1)'
${Else}
StrLen $2 $1
System::Call '*(&t$0,&t1,&t$2)i.r9'
System::Call 'KERNEL32::GetEnvironmentVariable(t "PATH", ir9, ir0)i.r0'
StrCpy $2 0
${IfThen} $0 > 0 ${|} IntOp $2 $0 - 1 ${|}
System::Call '*$9(&t$2,&t1.r2)' ; Store the last character from %PATH% in $2
StrCpy $3 ';'
${IfThen} $2 == ';' ${|} StrCpy $3 "" ${|}
System::Call 'KERNEL32::lstrcat(ir9, tr3)' ; Append ";" or ""
System::Call 'KERNEL32::lstrcat(ir9, tr1)'
System::Call 'KERNEL32::SetEnvironmentVariable(t "PATH", ir9)'
System::Free $9
${EndIf}
System::Store L
FunctionEnd
!endif
Section
Push "C:\RailsInstaller\Ruby2.1.0\bin"
Call ProcessEnvAppendPath
System::Call 'KERNEL32::SetEnvironmentVariable(t "RAILS_ENV", t "production")'
SetOutPath "C:\myapp" ; Sets the process working directory
ExecWait '"bundle" install --local' ; You should probably use the full path to bundle here.
SectionEnd
Another alternative would be to write the batch file on the fly and execute it with the nsExec
plugin.
Upvotes: 7