function ExecAndLogOutput(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer; const OnLog: TOnLog): Boolean;
Identical to Exec except:
Console programs are always hidden and the ShowCmd parameter only affects GUI programs, so always using SW_SHOWNORMAL instead of SW_HIDE is recommended.
If OnLog is set to nil then the output of the executed executable or batch file is logged in Setup's or Uninstall's log file and/or in the Compiler IDE's "Debug Output" view.
If OnLog is not set to nil then the output is sent to the specified function, line by line.
An exception will be raised if there was an error setting up output redirection (which should be very rare).
Parameter Wait must always be set to ewWaitUntilTerminated when calling this function.
TOnLog is defined as:
TOnLog = procedure(const S: String; const Error, FirstLine: Boolean);
Parameter S is the output line when Error is False, otherwise an error message. FirstLine is True if this is the first line of output from the program, otherwise False.
Error will be True if reading the output failed (which should be very rare), or if the output is too big. There is no further output after an error.
Output is limited to a total size of 10 million bytes or a maximum of 1 million lines.
var Line: String; procedure ExecAndGetFirstLineLog(const S: String; const Error, FirstLine: Boolean); begin if not Error and (Line = '') and (Trim(S) <> '') then Line := S; { First non-empty line found, store it } if FirstLine then Log('Output:'); Log(S); end; function ExecAndGetFirstLine(const Filename, Params, WorkingDir: String; var ResultCode: Integer): String; begin Line := ''; try ExecAndLogOutput(Filename, Params, WorkingDir, SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog); except Log(GetExceptionMessage); end; Result := Line; end;