[Windows] Chocolatey 內附的 7z.exe 和 Windows 平台不合?
今天在一台新裝好的 Windows 7 VM 上安裝了 Chocolatey,
也用它安裝了 greenshot 截圖軟體,
但接著用它安裝 sysinternals 這個工具軟體套件時,卻遇到了莫名其妙的錯誤:
Extracting C:\tools\cygwin\tmp\chocolatey\sysinternals\2016.04.28\SysinternalsSuite.zip to C:\ProgramData\chocolatey\lib\sysinternals\tools... ERROR: Exception calling "Start" with "0" argument(s): "The specified executable is not a valid application for this OS platform." The install of sysinternals was NOT successful. Error while running 'C:\ProgramData\chocolatey\lib\sysinternals\tools\chocolatey Install.ps1'. See log for details. Chocolatey installed 0/1 packages. 1 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). Failures - sysinternals (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\sysinternals\tools\chocolateyInstall.ps1'. See log for details.
如果去看 C:\ProgramData\chocolatey\logs\chocolatey.log 的話,
可以發現 Chocolatey 是想用 C:\ProgramData\chocolatey\tools\7z.exe,
來執行 SysinternalsSuite.zip 的解壓縮,卻遇到了錯誤~
直接執行 C:\ProgramData\chocolatey\tools\7z.exe 看看,
結果說這個 7z.exe 跟目前的 Windows 平台不合:
C:\Users\Administrator>c:\ProgramData\chocolatey\tools\7z.exe This version of c:\ProgramData\chocolatey\tools\7z.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.
我的 Windows 7 是 32-bit 的,難道這個 7z.exe 是 64-bit 的嗎?
用 Magic file 來看一下,還真的是 64-bit (x86-64) 的:
Administrator@localhost /cygdrive/c/ProgramData/chocolatey/tools $ file 7z* 7z.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows 7z.exe: PE32+ executable (console) x86-64, for MS Windows
這真的是很怪異的事情,Chocolatey 裝在 32-bit 平台上,自己附帶的 7z 卻是帶 64-bit 的,
看起來像是 Chocolatey 的 bug,但是稍微搜尋一下,似乎沒有這樣的錯誤回報,
而且我裝過幾台 Windows VM 也都沒有遇過這種問題…
懶得再找其他解法了,決定去裝一個 32-bit 的 7-zip,然後拿它的 7z.exe/dll 來用~
幸好 Chocolatey 這時還可以用來安裝 7zip 這個套件 (只要套件來源不是壓縮檔,就沒問題):
choco install 7zip
裝好之後,把 C:\Program Files\7-Zip 目錄下的 7z.exe 和 7z.dll 複製到 C:\ProgramData\chocolatey\tools 目錄下,
接著再用 choco 安裝 sysinternals 看看… 噹噹!沒有錯誤了:
C:\Users\Administrator>choco install sysinternals Installing the following packages: sysinternals By installing you accept licenses for the packages. sysinternals v2016.04.28 [Approved] Extracting C:\Users\Administrator\AppData\Local\Temp\chocolatey\sysinternals\2016.04.28\SysinternalsSuite.zip to C:\ProgramData\chocolatey\lib\sysinternals\tools... ...... The install of sysinternals was successful. Software installed to 'C:\ProgramData\chocolatey\lib\sysinternals\tools' Chocolatey installed 1/1 packages. 0 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
之後再用 Chocolatey 安裝其他的套件,也都沒有遇到問題了~
看來 Chocolatey 裡面還是有些 bug 的,遇到同樣問題的人可以試試這篇的解法囉~