How does output redirection work in Inno Setup?

I saw this question here: How to get the output of an Exec'ed program in Inno Setup?

But I can not get it to work myself, the code with comments is my attempt to do this work, but I resorted to the bat file because I could not perform the redirection. CacheInstanceName and CacheInstanceDir are global variables defined elsewhere:

 function CheckCacheExists(): Integer; var args: String; buffer: String; ResultCode: Integer; begin // args := 'qlist ' + CacheInstanceName + ExpandConstant(' nodisplay > {tmp}\appcheck.txt'); // MsgBox(args, mbInformation, MB_OK); // Exec(CacheInstanceDir + '\bin\ccontrol.exe', 'qlist ' + CacheInstanceName + ExpandConstant(' nodisplay > "{tmp}\appcheck.txt"'), '', SW_SHOW, ExtractTemporaryFile('checkup.BAT'); Exec(ExpandConstant('{tmp}\checkup.BAT'), CacheInstanceDir + ' ' + CacheInstanceName + ' ' + ExpandConstant('{tmp}'), '', SW_SHOW, ewWaitUntilTerminated, ResultCode); LoadStringFromFile(ExpandConstant('{tmp}\appcheck.txt'),buffer); if Pos('^', buffer) = 0 then begin Result := 0 end else begin Result := 1 end end; 

What am I doing wrong?

+4
source share
2 answers

The output redirection syntax is a command line function, not the core Windows APIs. Therefore, if you want to redirect the output, you need to call the command via {cmd} /c actual-command-line > output-file . Remember to include quotation marks where necessary, as {tmp} (and other constants) may contain spaces.

However, you should strongly consider overwriting all the files of this batch file into the actual code. Everything that you can do in the batch file, you can do either directly in the Inno script, or in the DLL that you call from the script. And this allows you to control error control and the format of any data that you want to receive.

+9
source

Try running the command directly on the command line with the arguments in the args line to see that the result may indicate a problem.

Also, make sure that the file you are trying to redirect to your output is not being used by another process. I found that when this happens, the actual command can successfully execute the Exec command returning True , but ResultCode indicates an error and no file is written to the file used in the redirect. In this particular file instance used by another instance, the SysErrorMessage(ResultCode) simply returns the Incorrect function . However, testing directly on the command line, as I mentioned, first returns that the file is being used by another process.

0
source

All Articles