Inno Setup – 由安装程序添加到PATH中的npm程序无法在从安装程序执行的batch file中识别

我已经创build了一个Windows安装程序使用Inno安装程序为我所做的应用程序。 作为安装程序的一部分,我已经安装了一些第三方应用程序,后面跟着一个batch file,执行一些npm命令可操作的程序或batch file。

一切安装好,但batch file运行时,我得到的消息

“npm”不被识别为内部或外部命令

命令不运行,所以应用程序不会打开。 但是,如果我保持原样,只需在安装后重新运行batch file,命令就会执行并且应用程序正常工作。 如何让batch file作为安装的一部分正确运行?

Inno Setup Run部分

 [Run] Filename: "{tmp}\Git-2.15.0-64-bit.exe"; Flags: waituntilterminated Filename: "{tmp}\rubyinstaller-2.3.3-x64.exe"; Flags: waituntilterminated Filename: "{tmp}\visualcppbuildtools_full.exe"; Flags: waituntilterminated Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\mongodb-win32-x86_64-2008plus-ssl-3.4.10-signed.msi"; WorkingDir: {tmp}; Flags: waituntilterminated Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\node-v6.11.0-x64.msi"; WorkingDir: {tmp}; Flags: waituntilterminated Filename: "{tmp}\setup.bat"; Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: shellexec postinstall skipifsilent 

batch file

 cd C:/Users/%USERNAME%/Documents/myApp/api/ call npm install -g bower call npm install -g grunt call npm install -g grunt-cli call npm config set msvs_version 2015 -global call npm install bcrypt -save call npm install cd ../admin/ call npm install -g bower call npm install -g grunt call npm install -g grunt-cli echo 1 | call gem install compass call bower install call npm install 

我猜测安装程序不会修改你的PATH,所以npm不会被别名作为命令。 如果通过使用可执行文件的绝对path调用npm,它应该按预期工作。

如果batch file在安装程序完成后工作,则其中一个子安装程序可能会将npm添加到PATH环境variables中。 但是对环境的更改不会自动应用于现有stream程(包括Inno Setup安装程序本身)及其子stream程(包括从Inno Setup安装程序执行的batch file),而仅适用于新stream程。

运行batch file之前,必须显式重新加载环境。

 [Run] Filename: "{tmp}\setup.bat"; BeforeInstall: RefreshEnvironment 

RefreshEnvironment实现显示在:
Inno Setup中[Run]程序的环境variables无法识别[不可用]


或者你当然可以在batch file中使用绝对path。 但为此,您将不得不根据安装位置即时生成batch file。

或者从npm目录运行batch file。 使用WorkingDir参数 。