What can I do in order to get the computer name on Raspbian Linux?
Strange.
What does echo $HOSTNAME give you in a console?
For me it gives the hostname on a RPI.
How
very strange....
I had done this to check why this happens:
As you can see it returns empty.
But:
$ echo $HOSTNAME
rpi4-gui
$
So executing the echo brings out the hostname, but listing
all the environment variables does not.
I started by listing them all when I found that the log was missing the hostname and env does not return the HOSTNAME entry...
Since the username is extracted using the same call I checked the definition of GetEnvironmentVariable found in osutil.inc below fpc rtl:
Function GetEnvironmentVariable(Const EnvVar : UnicodeString) : UnicodeString;
begin
result:=UnicodeString(GetEnvironmentVariable(AnsiString(EnvVar)));
end;
and:
Function GetEnvironmentVariable(Const EnvVar : String) : String;
begin
{ no need to adjust the code page of EnvVar to DefaultSystemCodePage, as only
ASCII identifiers are supported }
Result:=BaseUnix.FPGetenv(PChar(pointer(EnvVar)));
end;
There must be a difference in how echo grabs the variable HOSTNAME compared to USER, which is listed among the env vars.
So the question remains, how can I fix this?