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);
5
  • 1
  • 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? Nov 6, 2016 at 9: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. Nov 6, 2016 at 9:42
  • I mean the installer.log does not contain an output of your batch file. The extractor.log does. Nov 6, 2016 at 9:47
  • How can you new code "install to folders that contains names with spaces too."? It still does not quote the paths. Nov 7, 2016 at 10:53

1 Answer 1

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.

9
  • 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. Nov 6, 2016 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? Nov 6, 2016 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? Nov 6, 2016 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? Nov 6, 2016 at 16:44
  • Yes, I am distributing 7za.exe by myself, it's being copied to that location via the installer. Nov 7, 2016 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.