Thx for the sample, BUT indy is realy too oversized for querying only the IP =:-)
I have tried this:
function GetIPAddress: string;
var
theProcess: TProcess;
AddressString: AnsiString;
begin
try
theProcess := TProcess.Create(nil);
theProcess.Executable := 'hostname';
theProcess.Parameters.Add('-I');
theProcess.Options := [poUsePipes];
theProcess.Execute;
if theProcess.Output.NumBytesAvailable > 0 then
begin
SetLength(AddressString{%H-}, theProcess.Output.NumBytesAvailable);
theProcess.Output.ReadBuffer(AddressString[1], theProcess.Output.NumBytesAvailable);
end;
GetIPAddress := AddressString;
finally
theProcess.Free;
end;
end;
But i got no response. hostname on commandline works. If i work with the debugger now on a RasPi, i see it is working sometimes. I dig deeper and found, i have to use
heProcess.Options := [poUsePipes,poWaitOnExit];
Now i got a response. I have to test more.
A second improvement maybe
theProcess.Parameters.Add('--all-ip-addresses');
If i read the manuals correct.