简体   繁体   English

如何从Inno Setup调用“ npm install”?

[英]How to call “npm install” from Inno Setup?

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 . 我正在Inno Setup中编写安装程序,该程序安装Node.js,提取包含所有节点项目文件的zip文件,然后需要使用npm install节点应用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 . 手动过程包括打开命令提示符,浏览到这些文件所在的目录(在我的情况下,解压缩到与{app}文件夹设置相对应的Program Files文件夹),然后运行确切的命令行npm install --quiet However, when doing this in Inno Setup, it fails... 但是,在Inno Setup中执行此操作时,它会失败...

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. 我尝试将--quiet放入参数中,并使用此命令行作为参数调用cmd.exe ,以及许多其他尝试组合,但没有任何效果-执行只会失败。 The error I get is always The system cannot find the file specified. 我得到的错误始终是The system cannot find the file specified. .

How can I perform this node install while receiving the result/exit code? 接收结果/退出代码时如何执行此节点安装?

The problem was that I was using Exec but because of the nature of npm , it needed to use a shell command. 问题是我使用的是Exec但是由于npm的特性,它需要使用shell命令。 So instead, as TLama mentioned in the comments, I used ShellExec and everything worked. 因此,正如TLama在评论中提到的那样,我使用ShellExec并且一切正常。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM