Inno setup exec 函数不能完全工作

Inno setup exec function not fully working

我有一个 extractor.bat,我想在安装程序完成所有安装后 运行。

Extractor.bat 包含:

echo ARGUMENT 1 (PATH TO CUSTOM MODS): %1
echo ARGUMENT 2 (PATH TO EXTRACT TO): %2

set custommods=%1
set wotpath=%2

 IF EXIST %custommods%\*.zip (
    for /F "delims=" %%I IN (' dir /b /s /a-d %custommods%\*.zip ') DO (
        "7za.exe" x "%%I" -o%wotpath% -y
    )
 )
 IF EXIST %custommods%\*.7z (
    for /F "delims=" %%I IN (' dir /b /s /a-d %custommods%\*.7z ') DO (
        "7za.exe" x "%%I" -o%wotpath% -y
    )
 )

这是 ssPostInstall 代码的一部分:

  begin
if (CurStep=ssDone) then
begin
    Exec(ExpandConstant('{app}\extractor.bat'), ExpandConstant('{app}\custom_folder {app}\ > extractor.log'), '', SW_HIDE,     ewWaitUntilTerminated, ErrCode);
    Exec(ExpandConstant('{app}\res_mods\quick_fix.bat'), '', '', SW_HIDE,     ewWaitUntilTerminated, ErrCode);

    logfilepathname := expandconstant('{log}');
    logfilename := ExtractFileName(logfilepathname);
    newfilepathname := expandconstant('{app}\') + 'Installer.log';
    filecopy(logfilepathname, newfilepathname, false);
end;

结束;

问题是这个功能在我的电脑上运行良好,但在其他电脑上却无法运行,即使没有任何 antivir。为什么会这样?

我最近将该提取器执行移动到 [CODE] 部分,之前在 [运行] 部分作为一行:

Filename: "{tmp}\extractor.bat"; Parameters: " ""{app}\custom_folder"" ""{app}\"" ";  flags: runhidden;

它在那台特定的电脑上工作正常,但是当我使用代码部分时它不工作。我试图调试它,并注意到从 extractor.bar 到 Installer.log 的输出在第二行的中间被截断了,请参阅:

ARGUMENT 1 (PATH TO CUSTOM MODS): D:\Games\GameFolder
ARGUMENT 2 (PATH TO EXTRACT TO): of

有些奇怪 "of" 仅此而已。

编辑:

试过这个(玩 cmd 宏):

Exec(ExpandConstant('{cmd}'), '/C ' + ExpandConstant('{app}') + '\res_mods\quick_fix.bat', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ErrCode);

它根本没有执行,当然我在该文件夹中有一个 quick_fix.bat。

编辑2:

我目前正在使用这个:

        Exec(ExpandConstant('{app}\extractor.bat'), ExpandConstant('"{app}\Custom_mods" "{app}" > _Extractor.log'), '', SW_HIDE,     ewWaitUntilTerminated, ErrCode);

它有效,但不是对每个人都有效,对我来说有效。它也可以安装到包含带空格的名称的文件夹。

edit3:

[Files]
  Source: "{#CompPath}za.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
  Source: "{#CompPath}za.dll"; DestDir: "{tmp}"; Flags: deleteafterinstall
  Source: "{#CompPath}zxa.dll"; DestDir: "{tmp}"; Flags: deleteafterinstall

编辑:

我试图让 quick_fix.bat 工作,因为它是更简单的宏,而且它也没有被执行。

[Files]
  Source: "{#CompPath}\quick_fix.bat"; DestDir: "{app}\res_mods\"; Flags: deleteafterinstall

[CODE]
Exec(ExpandConstant('{cmd}'), '/C ' + ExpandConstant('{app}') + '\res_mods\quick_fix.bat', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ErrCode);

我看到的一个真正的问题是,您没有用双引号将安装文件夹的路径括起来。因此,如果它包含空格(它通常所做的,通常安装到 Program Files),您的批处理文件将会中断。

Exec(
  ExpandConstant('{app}\extractor.bat'),
  ExpandConstant('"{app}\custom_folder" "{app}\" > extractor.log'),
  '', SW_HIDE, ewWaitUntilTerminated, ErrCode);

因此,也许在安装程序运行的机器上,您将安装到一个没有空格的文件夹中。在机器上,安装程序不起作用,您安装到带空格的文件夹。