0

I have a extractor.bat that I would like to run in after installer finishes installing everything.

Extractor.bat contains :

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
    )
 )

This is part of ssPostInstall code:

  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;

end;

The problem is that this function is working fine on my PC but don't work on some other pc, even without any antivir. Why is that happening?

I've recently moved that extractor execution to the [CODE] section, previously was in [RUN] section as one line:

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

And it was working fine on that particular pc, however when I use the code section it's not working. I have tried to debug it, and noticed that output from extractor.bar to Installer.log is being cut out in middle of second line, see:

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

Some strange "of" and nothing more.

Edit:

Tried this (to toy with cmd macro):

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

and it wasn't executed at all, of course I have a quick_fix.bat in that folder present.

edit2:

I am currently using this:

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

And it works, but not for everyone, works for me thought. It can install to folders that contains names with spaces too.

edit3:

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

Edit:

I have tried to make quick_fix.bat to work, as it's easier macro, and it's not being executed as well.

[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);
Jerry Zoden
  • 332
  • 2
  • 9
  • 1
    Start here: [Debugging non-working batch file executed from Inno Setup installer](http://stackoverflow.com/questions/37324386/debugging-non-working-batch-file-executed-from-inno-setup-installer) – Martin Prikryl Nov 06 '16 at 09:26
  • 1
    *"noticed that output from extractor.bar to Installer.log is being cut out in middle of second line"* - Didn't you mean `extractor.log`, rather than `Installer.log`? – Martin Prikryl Nov 06 '16 at 09:38
  • Installer.log is a separate log, you can see it there in my code, but it's not affected by any problems. I only included it for better overview of this part. – Jerry Zoden Nov 06 '16 at 09:42
  • I mean the `installer.log` does not contain an output of your batch file. The `extractor.log` does. – Martin Prikryl Nov 06 '16 at 09:47
  • How can you new code *"install to folders that contains names with spaces too."*? It still does not quote the paths. – Martin Prikryl Nov 07 '16 at 10:53

1 Answers1

1

One real problem I can see is, that you do not wrap a path to installation folder with double-quotes. So, if it contains spaces (what it usually does, as one typically installs to Program Files), your batch file will break.

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

So maybe, on the machine, where the installer works, you install to a folder without spaces. While on the machine, where the installer does not work, you install to a folder with spaces.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • After I added missing quotas like in your example, the extractor log looks like this now: ARGUMENT 1 (PATH TO CUSTOM MODS): "D:\Games\Some_Game\custom_folder" ARGUMENT 2 (PATH TO EXTRACT TO): "D:\Games\Some_Game\" I am trying that different approach like you showed, with {cmd} etc. but I cannot make it work for some reason. – Jerry Zoden Nov 06 '16 at 10:55
  • Add you new code to your question. Add more debugging to the batch file. Did you try using an absolute path to the 7z? – Martin Prikryl Nov 06 '16 at 10:59
  • I have tried your second code, and it was not executed that's why I only tried to add missing quotas to previous code. Now it is looking like this: Exec(ExpandConstant('{app}\extractor.bat'), ExpandConstant('"{app}\custom_folder" "{app}\" > _Extractor.log'), '', SW_HIDE, ewWaitUntilTerminated, ErrCode); And no I have not try that absolute path, coud you give example how it would look like? – Jerry Zoden Nov 06 '16 at 12:53
  • Well, actually where do you expect the `7za.exe` to come from? It's not part of 7-zip installation. And even if it were, you cannot rely the user to have 7-Zip installed. Do you distribute the `7za.exe` yourself? – Martin Prikryl Nov 06 '16 at 16:44
  • Yes, I am distributing 7za.exe by myself, it's being copied to that location via the installer. – Jerry Zoden Nov 07 '16 at 10:49
  • What "that location"? If you rely on the `7za.exe`, that you distribute yourself, you should include the distribution code to your question - That's part of your task to post [mcve]. – Martin Prikryl Nov 07 '16 at 10:50
  • ok, the OP is updated, I see I'm copying it to tmp, maybe in this case I should copy it to app too. – Jerry Zoden Nov 07 '16 at 11:11
  • You run the batch file with no explicit working directory. So the batch file path (`{app}`) is implicitly used. So how can the batch file find the `7za.exe`? – Martin Prikryl Nov 07 '16 at 13:41
  • Also to capture errors, you have to redirect also the error output: `> extractor.log 2>&1`. – Martin Prikryl Nov 07 '16 at 14:30