我使用 NSIS 包創建了一個安裝程式來安裝我自己的軟體以及一些 3rd 方軟體,例如 Notepad 和 winPython。正在運行批處理腳本來安裝 notepad 和 winPython。打包到安裝程式中的 winPython 采用壓縮格式“winPython3940.7z”。作為安裝程式的一部分,使用以下.nsh腳本將其解壓縮到一個檔案夾中。
; --------------------------------------------------------------------------------------------
; Install Third Party Software
; --------------------------------------------------------------------------------------------
Section "Install Third Party Software"
; Execute Notepad installer
${If} $Notepad_userDecision == "1"
DetailPrint ""
DetailPrint "----------------- Install Notepad -----------------"
DetailPrint ""
DetailPrint "Create Notepad install batch..."
${textreplace::ReplaceInFile} "${TEMP_PATH}installer_template.bat" "${TEMP_PATH}install_notepad.bat" "#INSTALL_CMD" '"${TEMP_PATH}Notepad\npp.7.8.7.Installer.x64.exe" /S' "/S=1 /C=1 /AO=1 /PI=0 /PO=0" $0
DetailPrint "Execute Notepad install batch..."
nsExec::Exec "${TEMP_PATH}install_notepad.bat"
${EndIf}
; --------> PROBLEMATIC PART: Execute WinPython installer
${If} $WinPython_userDecision == "1"
; Delete old winPython Installation
DetailPrint ""
DetailPrint "----------------- Delete old WinPython installation -----------------"
DetailPrint ""
DetailPrint "Create WinPython uninstall batch..."
${textreplace::ReplaceInFile} "${TEMP_PATH}installer_template.bat" "${TEMP_PATH}uninstall_winpython.bat" "#INSTALL_CMD" 'if exist ("${PYTHON_PATH}" rmdir /s /q "${PYTHON_PATH}")' "/S=1 /C=1 /AO=1 /PI=0 /PO=0" $0
DetailPrint "Execute WinPython uninstall batch..."
nsExec::Exec "${TEMP_PATH}uninstall_winpython.bat"
DetailPrint ""
DetailPrint "----------------- Install WinPython -----------------"
DetailPrint ""
DetailPrint "Create WinPython install batch..."
${textreplace::ReplaceInFile} "${TEMP_PATH}installer_template.bat" "${TEMP_PATH}install_winPython.bat" "#INSTALL_CMD" 'if exist "C:\Program Files\7-Zip\7z.exe" ("C:\Program Files\7-Zip\7z.exe" x "${TEMP_PATH}WinPython\winPython3940.7z" -o${PYTHON_PATH})' "/S=1 /C=1 /AO=1 /PI=0 /PO=0" $0
DetailPrint "Execute WinPython install batch..."
nsExec::Exec "${TEMP_PATH}install_winPython.bat"
${EndIf}
SectionEnd
Notepad gets installed perfectly (without any popup cmd windows) as well as winPython, but the former has a couple of soft bugs. 2 batch scripts are being run to delete an old winPython installation and then installation the new one. When the installer is running, both of these scripts open up 2 individual cmd windows where the second one opens up after the first one is closed. Scripts get executed perfectly but they both contain "Not enough memory resources available to process this command" winPython uninstaller script's cmd window and winPython installer script's cmd window.
How do I resolve this issue?
uj5u.com熱心網友回復:
該訊息不是來自 NSIS,它必須來自批處理檔案中的某些內容,可能是 7-Zip。
沒有理由使用批處理檔案洗掉某些內容,只需使用 NSIS:
Section "Prepare Example"
CreateDirectory "$temp\fakepython\something\somethingelse"
CopyFiles /SILENT /FILESONLY "$WinDir\*.exe" "$temp\fakepython" ; Dummy files
SectionEnd
!include LogicLib.nsh
Var MyDetectedPythonPath
Section
StrCpy $MyDetectedPythonPath "$temp\fakepython" ; Replace this with the correct logic to find Python.
${If} ${FileExists} "$MyDetectedPythonPath\*" ; Probably a good idea to replace * with something like python.exe so you know you found the correct directory
RMDir /R "$MyDetectedPythonPath"
${EndIf}
DetailPrint "Installing python..."
StrCpy $1 '"$sysdir\cmd.exe" /C ping localhost' ; Replace this with your real command
nsExec::Exec '$1'
Pop $0
DetailPrint "Exit code $0"
SectionEnd
你也可以試試這個 7z 插件,而不是呼叫 7z-exe。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/435560.html
標籤:batch-file installation cmd nsis silent-installer
下一篇:批處理檔案FOR/f令牌不回圈
