[fpc-pascal] cannot read /sys/class/net/eth1/address even as root user on linux
Michael Van Canneyt
michael at freepascal.org
Thu Dec 5 12:45:40 CET 2013
On Thu, 5 Dec 2013, Dennis Poon wrote:
> I tried to read the mac address in the captioned file path.
> In terminal, I can simply 'cat' and display the mac address.
>
> In FPC, when I tried to use TFileStream to read it,
>
> FS := TFileStream.Create('/sys/class/net/eth1/address',
> fmOpenRead+fmShareDenyWrite);
>
> it raised "stream read error"
home: >./t
00:1f:d0:a2:df:c4
home: >cat t.pp
{$mode objfpc}
{$H+}
uses sysutils, classes;
Var
S : String;
begin
SetLength(S,100);
with TFileStream.Create('/sys/class/net/eth1/address', fmOpenRead+fmShareDenyWrite) do
try
SetLength(S,Read(S[1],100));
Writeln(S);
finally
free;
end;
end.
Works fine here. Permission problem on your machine maybe ?
Michael.
More information about the fpc-pascal
mailing list