NSI脚本等同于bat脚本

abh*_*7in 2 nsis batch-file

我在.bat文件中写了以下命令,对我很有用.现在我正在尝试编写一个NSIS基于图形的安装程序,并需要重现相同的NSIS.我不明白我怎么能做到这一点.

set PATH=%PATH%;C:\RailsInstaller\Ruby2.1.0\bin
set RAILS_ENV=production
cd C:\myapp
bundle install --local
Run Code Online (Sandbox Code Playgroud)

我想知道如何编写一个nsi脚本,它相当于上面的命令一个接一个地在shell中运行.

And*_*ers 7

在NSIS中更新%PATH%时需要小心,因为NSIS字符串长度限制短于%PATH%长度限制.您可以通过直接调用Windows API来解决此问题:

!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
Run Code Online (Sandbox Code Playgroud)

另一种方法是动态编写批处理文件并使用nsExec插件执行它.