0

I'm trying to call ngen with a CMD-script to create a native image of the application that is installed with InnoSetup. For that I run said script by calling ShellExec in the curStepChanged function when Curstep is ssPostInstall. The script itself looks up the location of ngen and calls it with the path of the application as parameter. The problem is that the script is stopped after aprox. 1 second without any errors. ShellExec returns true and the logfile created by the script is empty.

Here the Details: InnoSetup:

procedure CurStepChanged(CurStep: TSetupStep);
var
Param : String;
ResultCode : Integer;
begin
    if CurStep=ssPostInstall then begin
        try
            ProgressPage.SetProgress(0,2);
            ProgressPage.SetText('Tell Application about the Database','');
            ProgressPage.Show;

            Exec(ExpandConstant('{tmp}') + '\XMLAndIniReplacer.exe',ExpandConstant('{app}')+'\Application.exe.config'+ ' ' +DBPage.Values[0] + ' ' + DBPage.Values[1] + ' ' + DBPage.Values[2] + ' ' + DBPage.Values[3] +  ' ' + ExpandConstant('{app}')+'\Application.ini' + ' ' + ExpandConstant('{language}'),'', SW_HIDE, ewWaitUntilTerminated, ResultCode)   

            ProgressPage.SetProgress(1,2);
            ProgressPage.SetText('Make Application faster ','This operation could take a few minutes');

            Param := '"' + ExpandConstant('{app}') + '"';

            if not ShellExec('', ExpandConstant('{tmp}') + '\ngen-run.cmd', Param,'', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
                MsgBox(SysErrorMessage(ResultCode), mbError, MB_OK);
            end;
            ProgressPage.SetProgress(2,2);
        finally
            ProgressPage.Hide;
        end;
    end;       
end;

CMD-File:

for /f "tokens=3* delims=    " %%a in ('reg.exe query   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework /v InstallRoot') do set "UTILPATH=%%a\v4.0.30319\ngen.exe"
echo %1
echo %2
echo %UTILPATH%
%UTILPATH% %2 %1\Application.exe > ngen.log

Everything works just fine, it's just that the script is called, open for about a second, and closes without telling me anything. Also there is no native image as a single second for a several megabyte heavy .exe would be ridiculously fast. Also the black magic that is casted in the CMD-File is the work of someone else. I can't tell what happens in there. I only know, that it calls ngen with the application as parameter. So far it worked perfectly fine. So whats wrong here?

EaranMaleasi
  • 895
  • 1
  • 13
  • 32
  • `for /f "tokens=3* delims= " %%a ...` returns no output with multiple spaces in `delims= "`. Try default delimiter as follows: `for /f "tokens=3*" %%a ...` – JosefZ Sep 30 '15 at 16:37
  • `delims` is intended to be a tab and a space, right? – aschipfl Sep 30 '15 at 16:42
  • Does the batch file work if you execute it standalone? – Martin Prikryl Oct 01 '15 at 06:15
  • The Script on its own worked just fine everywhere it was used. And yes, the `delims` is intended to be a tab and a space. Throwing it away does not affect the script as far as I can tell. – EaranMaleasi Oct 01 '15 at 06:23
  • Run the command line this to make sure you capture any possible errors: `Exec(ExpandConstant('{cmd}'), '/C ' + ExpandConstant('{tmp}') + '\ngen-run.cmd >c:\somewrittablepath\ngen.log 2>&1', ExpandConstant('{tmp}'), SW_SHOW, ewWaitUntilTerminated, ResultCode)` and remove the `> ngen.log` redirect in the batch-file itself. – Martin Prikryl Oct 01 '15 at 06:26
  • Or maybe, just put a `pause` at the end of the batch file (and remove the redirect). – Martin Prikryl Oct 01 '15 at 06:27
  • Okay... so now, the command is executed in the directory of the application. Had to remove the `\` before the `Application` on the last line as `%1` seems to be empty now. Note that I also took in @JosefZ's modification. The log now shows everything as if I would've run the script by hand, but the console closes itself, again, after ~1 second. The log shows exactly nothing. Also pause didn't do anything. – EaranMaleasi Oct 01 '15 at 07:41
  • Try `echo %date% %time% "%1" "%2" "%UTILPATH%" >> ngen.log` just before `"%UTILPATH%" %2 %1\Application.exe >> ngen.log 2>&1` and then `pause`. (note `>> ngen.log 2>&1`redirection) – JosefZ Oct 01 '15 at 08:56
  • Append (not replace) your current version of the batch file and the code to the question. – Martin Prikryl Oct 02 '15 at 14:59

1 Answers1

1

To clear things up, I solved this by letting InnoSetup do the work the script would've done. Extracting the ngen Path from the registry, running ngen with the correct path as parameter. That way I can control what ngen is doing, and I have one less thing of which I don't know how it works.

EaranMaleasi
  • 895
  • 1
  • 13
  • 32