tags:

views:

299

answers:

1

Is it possible to get the output of an exec'ed executable. I want to show the user a info query page but show the default value of mac address in the input box. Is there any other way to reach the same goal?

+3  A: 

Yes, use redirection of the standard output to a file:

[Code]
function NextButtonClick(CurPage: Integer): Boolean;
var
  TmpFileName, ExecStdout: string;
  ResultCode: integer;
begin
  if CurPage = wpWelcome then begin
    TmpFileName := ExpandConstant('{tmp}') + '\ipconfig_results.txt';
    Exec('cmd.exe', '/C ipconfig /ALL > "' + TmpFileName + '"', '', SW_HIDE,
      ewWaitUntilTerminated, ResultCode);
    if LoadStringFromFile(TmpFileName, ExecStdout) then begin
      MsgBox(ExecStdout, mbInformation, MB_OK);
      // do something with contents of file...
    end;
    DeleteFile(TmpFileName);
  end;
  Result := True;
end;

Note that there may be more than one network adapter, and consequently several MAC addresses to choose from.

mghie