2014-05-02 112 views
1

我在安装Node.js的Inno Setup中编写安装程序,提取包含所有节点项目文件的zip文件,然后需要使用npm install安装节点应用程序。如何从Inno Setup调用“npm install”?

手动过程包括打开一个命令,浏览到这些文件的目录(在我的情况中提取与{app}文件夹设置对应其程序文件夹),然后运行确切命令行npm install --quiet。然而,在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; 

我试图把在参数--quiet以及调用cmd.exe使用此命令行参数,并尝试多种组合方式,但没有任何工作 - 执行失败。我得到的错误始终是The system cannot find the file specified.

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

+0

假设'npm'是可执行文件,你应该写类似'Exec的( '故宫', '安装--quiet',ExpandConstant( '{}应用'),SW_SHOWNORMAL,ewWaitUntilTerminated,结果) ',其中'npm'预计可以在'{app}'文件夹或例如路径由'PATH'环境变量注册。 – TLama

+0

@TLama'npm'不是可执行文件,这就是为什么我无法工作。至少它不是这个文件夹中的可执行文件。我对“Node.js”和“npm”一无所知,但我试图用Inno Setup复制命令行中的内容。 –

+0

请注意,命令提示符使用Windows Shell,因此它不仅可以运行可执行文件(例如批处理文件)。话虽如此,更接近的是Inno Setup中的ShellExec功能。当然,我可以告诉,如果'npm'不是可执行文件,使用'ShellExec'函数。 – TLama

回答

2

问题是我使用的是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;