Recent

Author Topic: Environment Variable  (Read 1598 times)

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Environment Variable
« 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)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Environment Variable
« Reply #1 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.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Environment Variable
« Reply #2 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Re: Environment Variable
« Reply #3 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.
« Last Edit: January 24, 2020, 11:34:12 pm by curiosus »

 

TinyPortal © 2005-2018