Lazarus

Programming => General => Topic started by: MaxCuriosus on January 24, 2020, 04:26:13 pm

Title: Environment Variable
Post by: MaxCuriosus on January 24, 2020, 04:26:13 pm
With Lazarus2.0.2/FPC3.0.4 on a Debian9 system,

GetEnvironmentVariable('USERNAME') yields the correct name, while

GetEnvironmentVariable('COMPUTERNAME') yields an empty string.

Why?

(in the terminal the various options of "uname" give the proper info)
Title: Re: Environment Variable
Post by: marcov on January 24, 2020, 04:34:53 pm
getenvironmentvariable doesn't show uname, but the environment.

So do a

"export" and make sure it is listed there.
Title: Re: Environment Variable
Post by: lucamar on January 24, 2020, 04:54:18 pm
To look to all the environment variables you can use a small program like this:

Code: Pascal  [Select][+][-]
  1. program ShowEnv;
  2.  
  3. uses sysutils;
  4.  
  5. var
  6.  i: Integer;
  7.  
  8. begin
  9.   for i := 1 to GetEnvironmentVariableCount do
  10.     writeln(GetEnvironmentString(i));
  11. end.

Note that you can get the result of running uname very easily from your application--for example using RunCommand() (in the Process unit of the FCL)--which would allow you to get the info you want without having to "export" to an environment variable.
Title: Re: Environment Variable
Post by: MaxCuriosus on January 24, 2020, 11:25:23 pm
1) Thank you marcov for the "export" suggestion. That showed me that the desired environment variable was not present.

2) Thank you lucamar for the code suggestion and the use of "RunCommand" with which I am already familiar.
That solves my problem.
TinyPortal © 2005-2018