2

I have created a Windows installer using Inno Setup for an app I have made. As part of the installer I have included the installation of some third party applications followed by a batch file, to execute a number of npm command operable program or batch file.

Everything installs okay but when the batch file runs I get the message

'npm' is not recognized as an internal or external command

The commands don't run and so the app won't open. However, if I leave everything as it is and just rerun the batch file again after the installation, the commands execute and the app works fine. How can I get the batch file to run properly as part of the installation?

Inno Setup Run Section

[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 
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Deef
  • 49
  • 2
  • I left out Filename: "{tmp}\python-3.5.4-amd64-webinstall.exe"; Flags: waituntilterminated was also installed – Deef Dec 06 '17 at 19:18

2 Answers2

0

If the batch file works after your installer completes, one of the subinstallers probably adds npm to the PATH environment variable. But changes to environment does not apply automatically to existing processes (that includes Inno Setup installer itself) and their child processes (that includes your batch file executed from Inno Setup installer), only to new processes.

You would have to explicitly reload the environment before running the batch file.

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

Where the RefreshEnvironment implementation is shown in:
Environment variable not recognized [not available] for [Run] programs in Inno Setup


Or you can of course use an absolute path in the batch file. But for that you would have to generate the batch file on the fly based on installation location.

Or run the batch file from the npm directory. Use WorkingDir parameter for that.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
-1

I'm guessing the installer doesn't modify the PATH for you, so npm isn't being aliased as a command. If you invoke npm by using the absolute path to the executable, it should work as expected.

posit labs
  • 8,951
  • 4
  • 36
  • 66