Frage

I'm writing an installer in Inno Setup which installs Node.js, extracts a zip file containing all the node project files, and then needs to install the node app using npm install.

The manual process consists of opening a command prompt, browsing to the directory where these files are (in my case extracted to its Program Files folder corresponding with the {app} folder setting), and then running that exact command line npm install --quiet. However, when doing this in Inno Setup, it fails...

function InstallNodeApp: Integer;
var
  C: String;
begin
  C:= 'npm install --quiet';
  if not Exec(C, '', ExpandConstant('{app}'), SW_SHOWNORMAL, ewWaitUntilTerminated, Result) then begin
    Result:= -1;
  end;
end;

I've tried putting --quiet in the parameters as well as calling cmd.exe with this command line as a parameter, and many other combinations of attempts, but nothing is working - the execution just fails. The error I get is always The system cannot find the file specified..

How can I perform this node install while receiving the result/exit code?

War es hilfreich?

Lösung

The problem was that I was using Exec but because of the nature of npm, it needed to use a shell command. So instead, as TLama mentioned in the comments, I used ShellExec and everything worked.

function InstallNodeApp: Integer;
var
  C, P, D: String;
begin
  C:= 'npm';
  P:= 'install --silent';
  D:= ExpandConstant('{app}');
  if not ShellExec('', C, P, D, SW_HIDE, ewWaitUntilTerminated, Result) then begin
    Result:= -1;
  end;
end;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top