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

我在安装Node.js的Inno Setup中编写一个安装程序,提取一个包含所有节点项目文件的zip文件,然后需要使用npm install来安装节点应用npm install

手动过程包括打开命令提示符,浏览到这些文件所在的目录(在我的案例中解压缩到与其{app}文件夹设置对应的Program Files文件夹中),然后运行该命令行npm install --quiet 。 但是,在Inno安装程序中执行此操作时,它将失败…

 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; 

我已经尝试把--quiet参数以及调用这个命令行的cmd.exe作为参数,以及其他许多尝试的组合,但没有任何工作 – 执行失败。 我得到的错误总是The system cannot find the file specified.

如何在接收结果/退出代码时执行此节点安装?

问题是我使用Exec但由于npm的特性,它需要使用shell命令。 所以相反,正如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;