-1

I have a peculiar problem and have exhausted all threads I can find on the issue.

SEE UPDATE BELOW

I am trying to run a bat file in the code section of an INNO installer via the Exec() function. The bat takes in an argument containing double quotes and then launches a java program (passes the argument on). Via INNO Exec(), the bat fails to launch a java program. However, if I open cmd and run the command myself it launches successfully.

INNO code:

    [Setup]
AppName=blah
AppVersion=1.0
AppPublisher=blah
AppPublisherURL=www.blah.com
DefaultDirName={pf}\blah
DefaultGroupName=blah
AllowNoIcons=no
OutputBaseFilename=blah 
SolidCompression=yes
Compression=lzma
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x64
AlwaysRestart=no
PrivilegesRequired=admin 

[Dirs]
Name: "{app}";

[Files]
Source: "..\dummy3.txt";DestDir: "{app}"; Flags: ignoreversion 64bit deleteafterinstall; BeforeInstall: InstallExt();

[Code]
{ Install SPSS Extensions from SPEs }
procedure InstallExt();
var
  ResultCode: integer;
begin
  if not Exec('"C:\Program Files\IBM\SPSS\Statistics\25\installextbundles.bat"', '–download no –source "C:\Program Files\blah"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  begin
    MsgBox('Could not install OLSPS Extensions: ' + IntToStr(ResultCode) ,mbError, mb_Ok);
  end;        
end;

I imagine that INNO is somehow changing the parameters passed to the bat / cmd. Any Ideas?

~~~~~~~ UPDATE ~~~~~~

As suggested below in the comments (ref: Debugging non-working batch file or command executed from Inno Setup installer), I ran it so that cmd stays open and commented out the ECHO off of the bat file.

[Run] 
Filename: C:\Windows\SysWOW64\cmd.exe; Parameters: '/K "C:\Program files\IBM\SPSS\Statistics\25\installextbundlesdebug.bat" –download no –source "C:\Program files\blah"'

I Also ran it manually with ECHO on via CMD to compare the two.

"C:\Program files\IBM\SPSS\Statistics\25\installextbundlesdebug.bat" –download no –source "C:\Program files\blah"

The result: With a minor tweak to the bat file, I got it echoing the same output whether via manual cmd or exec(), with the exception that via cmd it then successfully launched an external java program and failed to do so via INNO. Exact same echo'ed output.

T.Donaldson
  • 115
  • 9
  • 1
    Why do you even try `ShellExec`? If you have no particular reason, focus your question solely on `Exec` (the question is way to long already anyway). + Remove the double quotes from `'"C:\Program Files\IBM\SPSS\Statistics\25\installextbundles.bat"'`. + Does the batch file display any errors, when executed from Inno Setup? See [Debugging non-working batch file or command executed from Inno Setup installer](https://stackoverflow.com/q/37324386/850848). – Martin Prikryl Jun 14 '18 at 09:09
  • Thanks for that guidance Martin. See update. Any ideas? – T.Donaldson Jun 14 '18 at 09:56
  • *"it was launching in 32bit if I launched {cmd}"* - I do not see any evidence of that in your question. How do you check that? + I do not get your question with `PROGRA~1` - Why should it resolve? - I do not see anything in your batch file that should cause the path to resolve. And you did not really show us how you *"manually run [the batch file] in CMD"* – Martin Prikryl Jun 14 '18 at 10:47
  • Thanks Again. See updated with evidence of "it was launching in 32bit if I launched {cmd}" and "show us how you manually run [the batch file] in CMD"............ "I do not get your question with PROGRA~1 - Why should it resolve?" - I'm not sure it should, I just see that it DID resolve when successfully run manually, so thought it may be relevant. – T.Donaldson Jun 14 '18 at 11:11
  • 1
    1) The difference `C:\WINDOWS\system32` vs. `C:\Users\Tyler` is due to your starting/working directory, nothing to do with 32/64-bit. 2) The difference `"C:\Program Files\blah"` vs. `C:\PROGRA~1\blah` is because you run the script like that! Note the `C:\PROGRA~1\blah` in your `[Run]` section entry, vs. `"C:\Program Files\blah"` when *"manually run in CMD"*. – Martin Prikryl Jun 14 '18 at 11:20
  • 1
    I agree with @MartinPrikryl: Your question says *When I do these two totally different things two totally different ways, they don't have the same results.* Why would you expect them to? The way you're doing it when it works is done correctly because you start in the proper directory and pass parameters correctly , the totally different way doesn't because you're starting in a different directory and passing different parameters. – Ken White Jun 14 '18 at 12:43
  • Windows has short versions of paths and that is when a ~ would be visible. I agree with the others. – Andrew Truckle Jun 15 '18 at 04:10
  • Thanks for all the comments.. apologies for the shoddy editing leading to confusion.. it isn't an INNO issue and I have just made a work around – T.Donaldson Jun 15 '18 at 10:04

1 Answers1

0

Ok, so it doesn't have anything to do with INNO exec() breaking things because I can run the bat file via cmd manually and get it to echo the exact same output as it echos via INNO exec(). So it must be an issue somehow (despite admin privileges) with permissions or the bat/java itself.

T.Donaldson
  • 115
  • 9