5

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

But I can't get it to work myself, the commented out code are my attempts to make this work, but I resorted to a bat file because I couldn't make my redirection work. CacheInstanceName and CacheInstanceDir are global variable 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?

0

2 Answers 2

10

The output redirection syntax is a feature of the command prompt, not the core Windows APIs. Therefore if you want to redirect output then you need to invoke the command via {cmd} /c actual-command-line > output-file. Don't forget to include quotes where appropriate, as {tmp} (and other constants) may contain spaces.

However, you should strongly consider rewriting whatever is in that batch file into actual code. Anything you can do in a batch file you can do either directly in the Inno script or in a DLL that you call from the script. And this permits you greater control over error checking and the format of whatever data you want to retrieve.

Sign up to request clarification or add additional context in comments.

1 Comment

Which, funnily enough, is what the answer to the other question said (just less detail :)
0

Try running the command directly on your command line with the arguments in your args string to see what the result is which may give an indication of the problem.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.