Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-03

SysUtils.GetEnvironmentVariable

24 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas

Hi,

I think SysUtils.GetEnvironmentVariable has a problem. I tried to use GetEnvironmentVariable on WinXP and Win7. Sometimes works on WinXP, others not. But never worked on Win7.

I asked some friends to test on Linux and did not work too.

My FPC is 2.6.1 rev 20648 on WinXP.

The test:
1- Create a Environment Variable (eg: FOO).
2- Try this:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(SysUtils.GetEnvironmentVariable('FOO'));
end;

Marcos Douglas

Reply by email

Michael Van Canneyt
to Marcos Douglas
Marcos Douglas wrote 19 lines
Hi, I think SysUtils.GetEnvironmentVariable has a problem. I tried to use GetEnvironmentVariable on WinXP and Win7. Sometimes works on WinXP, others not. But never worked on Win7. I asked some friends to test on Linux and did not work too. My FPC is 2.6.1 rev 20648 on WinXP. The test: 1- Create a Environment Variable (eg: FOO). 2- Try this: procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(SysUtils.GetEnvironmentVariable('FOO')); end;

Just tested.

Works fine on linux, provided the environment variable is defined BEFORE the program is started, and in the terminal that starts the program. (perfectly normal on linux)

So if you run the program under the IDE, the environment variable must be defined in the session that starts the IDE, BEFORE the ide is started.

Cannot comment on Windows, but I would be very surprised if it does not work, since many of our programs rely on it.

There again, be careful WHEN you define the environment variable. Before or after starting the application.

Michael.

Reply by email

Marcos Douglas
to Michael Van Canneyt
Michael Van Canneyt wrote 39 lines
On Wed, 28 Mar 2012, Marcos Douglas wrote: > Hi, > > I think SysUtils.GetEnvironmentVariable has a problem. > I tried to use GetEnvironmentVariable on WinXP and Win7. Sometimes > works on WinXP, others not. But never worked on Win7. > > I asked some friends to test on Linux and did not work too. > > My FPC is 2.6.1 rev 20648 on WinXP. > > The test: > 1- Create a Environment Variable (eg: FOO). > 2- Try this: > > procedure TForm1.Button1Click(Sender: TObject); > begin >  ShowMessage(SysUtils.GetEnvironmentVariable('FOO')); > end; > Just tested. Works fine on linux, provided the environment variable is defined BEFORE the program is started, and in the terminal that starts the program. (perfectly normal on linux) So if you run the program under the IDE, the environment variable must be defined in the session that starts the IDE, BEFORE the ide is started. Cannot comment on Windows, but I would be very surprised if it does not work, since many of our programs rely on it. There again, be careful WHEN you define the environment variable. Before or after starting the application.

I know that I have to define the environment variable before or after starting the application or IDE.
As I said, works in WinXP... but I had a little problem with a client using Win7 so, I talked about this on lazarus-br list and asked to somebody do the test on Win7 and they said the test did not work so, I wrote here.

Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas
Marcos Douglas wrote 48 lines
On Wed, Mar 28, 2012 at 6:40 PM, Michael Van Canneyt wrote: > > > > On Wed, 28 Mar 2012, Marcos Douglas wrote: > >> Hi, >> >> I think SysUtils.GetEnvironmentVariable has a problem. >> I tried to use GetEnvironmentVariable on WinXP and Win7. Sometimes >> works on WinXP, others not. But never worked on Win7. >> >> I asked some friends to test on Linux and did not work too. >> >> My FPC is 2.6.1 rev 20648 on WinXP. >> >> The test: >> 1- Create a Environment Variable (eg: FOO). >> 2- Try this: >> >> procedure TForm1.Button1Click(Sender: TObject); >> begin >> ShowMessage(SysUtils.GetEnvironmentVariable('FOO')); >> end; >> > > Just tested. > > Works fine on linux, provided the environment variable is defined BEFORE > the program is started, and in the terminal that starts the program. > (perfectly normal on linux) > > So if you run the program under the IDE, the environment variable must be > defined in the session that starts the IDE, BEFORE the ide is started. > > Cannot comment on Windows, but I would be very surprised if it does not > work, since many of our programs rely on it. > > There again, be careful WHEN you define the environment variable. Before > or after starting the application. I know that I have to define the environment variable before or after starting the application or IDE. As I said, works in WinXP... but I had a little problem with a client using Win7 so, I talked about this on lazarus-br list and asked to somebody do the test on Win7 and they said the test did not work so, I wrote here.

You could use Process Explorer to inspect the Environment of your process.

That being said I just tested the following program:

=== source begin ===

program envtest;
uses
   SysUtils;
var
   i: LongInt;
begin
   if ParamCount = 0 then
     Writeln('Usage: ', ExtractFileName(ParamStr(0)), ' ENVVAR [ENVVAR
[...]]')
   else begin
     for i := 1 to ParamCount do
	  Writeln(ParamStr(i), ' = ', GetEnvironmentVariable(ParamStr(i)));
   end;
end.

=== source end ===

I tested it in a CMD session on a Windows 7:

=== output begin ===

P:\tests\oneshots>set FOO=bar

P:\tests\oneshots>.\envtest.exe FOO
FOO = bar

=== output end ===

Please note that in "cmd" the following are different:

set FOO=bar
=> "FOO" -> "bar"
set FOO = bar
=> "FOO " -> " bar"
set FOO= bar
=> "FOO" -> " bar"
set FOO =bar
=> "FOO " -> "bar"

Regards,
Sven

Reply by email

Mark Morgan Lloyd
to Marcos Douglas: On Wed, Mar 28, 2012 at 6:40 PM, Michael Van Canneyt I know that I have to define the…
Marcos Douglas wrote 6 lines
I know that I have to define the environment variable before or after starting the application or IDE. As I said, works in WinXP... but I had a little problem with a client using Win7 so, I talked about this on lazarus-br list and asked to somebody do the test on Win7 and they said the test did not work so, I wrote here.

I think the absolutely crucial thing here is to ask what the relationship between the session in which the shell/environment variable was defined, and the FPC program.

If the variable is set and the program is run from the same prompt, provided that it's not messed up by extra spaces or by e.g. an interposed command.com, then it should work.

In any other case it might work, and it's entirely reasonable to assume that the extent to which variables are passed between running processes will vary wildly with OS version.

I suggest the *first* thing to do is to confirm that the variable has stuck by using the set command. After that try running the Pascal program.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Marcos Douglas
to Sven Barth: You could use Process Explorer to inspect the Environment of your process. That being…
Sven Barth wrote 105 lines
Am 29.03.2012 05:31, schrieb Marcos Douglas: > On Wed, Mar 28, 2012 at 6:40 PM, Michael Van Canneyt >  wrote: >> >> >> >> >> On Wed, 28 Mar 2012, Marcos Douglas wrote: >> >>> Hi, >>> >>> I think SysUtils.GetEnvironmentVariable has a problem. >>> I tried to use GetEnvironmentVariable on WinXP and Win7. Sometimes >>> works on WinXP, others not. But never worked on Win7. >>> >>> I asked some friends to test on Linux and did not work too. >>> >>> My FPC is 2.6.1 rev 20648 on WinXP. >>> >>> The test: >>> 1- Create a Environment Variable (eg: FOO). >>> 2- Try this: >>> >>> procedure TForm1.Button1Click(Sender: TObject); >>> begin >>>  ShowMessage(SysUtils.GetEnvironmentVariable('FOO')); >>> end; >>> >> >> Just tested. >> >> Works fine on linux, provided the environment variable is defined BEFORE >> the program is started, and in the terminal that starts the program. >> (perfectly normal on linux) >> >> So if you run the program under the IDE, the environment variable must >> be >> defined in the session that starts the IDE, BEFORE the ide is started. >> >> Cannot comment on Windows, but I would be very surprised if it does not >> work, since many of our programs rely on it. >> >> There again, be careful WHEN you define the environment variable. Before >> or after starting the application. > > > I know that I have to define the environment variable before or after > starting the application or IDE. > As I said, works in WinXP... but I had a little problem with a client > using Win7 so, I talked about this on lazarus-br list and asked to > somebody do the test on Win7 and they said the test did not work so, I > wrote here. You could use Process Explorer to inspect the Environment of your process. That being said I just tested the following program: === source begin === program envtest; uses  SysUtils; var  i: LongInt; begin  if ParamCount = 0 then    Writeln('Usage: ', ExtractFileName(ParamStr(0)), ' ENVVAR [ENVVAR [...]]')  else begin    for i := 1 to ParamCount do          Writeln(ParamStr(i), ' = ', GetEnvironmentVariable(ParamStr(i)));  end; end. === source end === I tested it in a CMD session on a Windows 7: === output begin === P:\tests\oneshots>set FOO=bar P:\tests\oneshots>.\envtest.exe FOO FOO = bar === output end === Please note that in "cmd" the following are different: set FOO=bar  => "FOO" -> "bar" set FOO = bar  => "FOO " -> " bar" set FOO= bar  => "FOO" -> " bar" set FOO =bar  => "FOO " -> "bar" Regards, Sven

The application is installed and the system variable is created. The application and others process should be use this variable just calling SysUtils.GetEnvironmentVariable.

Marcos Douglas

Reply by email

Marcos Douglas
to Mark Morgan Lloyd: I think the absolutely crucial thing here is to ask what the relationship between the…
Mark Morgan Lloyd wrote 13 lines
Marcos Douglas wrote: > I know that I have to define the environment variable before or after > starting the application or IDE. > As I said, works in WinXP... but I had a little problem with a client > using Win7 so, I talked about this on lazarus-br list and asked to > somebody do the test on Win7 and they said the test did not work so, I > wrote here. I think the absolutely crucial thing here is to ask what the relationship between the session in which the shell/environment variable was defined, and the FPC program.

Nothing.

If the variable is set and the program is run from the same prompt, provided that it's not messed up by extra spaces or by e.g. an interposed command.com, then it should work.

No. The variable is set using a install program or Windows.

Show quoted text 6 lines
In any other case it might work, and it's entirely reasonable to assume that the extent to which variables are passed between running processes will vary wildly with OS version. I suggest the *first* thing to do is to confirm that the variable has stuck by using the  set  command. After that try running the Pascal program.

No command set is used.
The variable has been created in the Windows System Variables.

Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas: The application is installed and the system variable is created. The application and…
Marcos Douglas wrote
The application is installed and the system variable is created. The application and others process should be use this variable just calling SysUtils.GetEnvironmentVariable.

Then let a FPC program print all passed environment variables as a test:

=== source begin ===

program envtest;
var
   i: LongInt;
begin
   for i := 0 to GetEnvironmentVariableCount do
     Writeln(GetEnvironmentString(i)); // Note: this will include
"name=value" unlike GetEnvironmentVariable
end.

=== source end ===

Also - as I already wrote - you can use the Process Explorer ( http://technet.microsoft.com/de-de/sysinternals/bb896653 ) to check whether the application does indeed contain the environment variable.

Regards,
Sven

Reply by email

Mattias Gaertner
to Marcos Douglas: The application is installed and the system variable is created. The application and…

Marcos Douglas hat am 29. März 2012 um 13:06 geschrieben:

Show quoted text 19 lines
[...]> > === output end === > > Please note that in "cmd" the following are different: > > set FOO=bar > => "FOO" -> "bar" > set FOO = bar > => "FOO " -> " bar" > set FOO= bar > => "FOO" -> " bar" > set FOO =bar > => "FOO " -> "bar" > > Regards, > Sven The application is installed and the system variable is created. The application and others process should be use this variable just calling SysUtils.GetEnvironmentVariable.

In former Windows versions sometimes you had to logout/login to get the new environment variables.
Is this still the case with Windows 7?

Mattias

Reply by email

Unknown author
to Marcos Douglas: On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd Nothing. No. The variable is set using…
Marcos Douglas wrote 33 lines
On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd wrote: > Marcos Douglas wrote: > >> I know that I have to define the environment variable before or after >> starting the application or IDE. >> As I said, works in WinXP... but I had a little problem with a client >> using Win7 so, I talked about this on lazarus-br list and asked to >> somebody do the test on Win7 and they said the test did not work so, I >> wrote here. > > > I think the absolutely crucial thing here is to ask what the relationship > between the session in which the shell/environment variable was defined, and > the FPC program. Nothing. > If the variable is set and the program is run from the same prompt, provided > that it's not messed up by extra spaces or by e.g. an interposed > command.com, then it should work. No. The variable is set using a install program or Windows. > In any other case it might work, and it's entirely reasonable to assume that > the extent to which variables are passed between running processes will vary > wildly with OS version. > > I suggest the *first* thing to do is to confirm that the variable has stuck > by using the  set  command. After that try running the Pascal program. No command set is used. The variable has been created in the Windows System Variables.

He means that you must check using the SET command in a command window.

So run - execute : CMD.exe

In the command terminal that opens, type 'SET' (+enter)

Your variable should show up in the list of environment variables.

Please note that under windows 7, there are system environment variables, and user variables.

If the application is installed using user A, but user B runs your program, it is possible that the environment variable is not shown.

It depends on how the variable was created by your installer. To check this, the command window can be used.

The RTL of Free Pascal just calls the Windows API to get the environment variable. No magic is performed.

Michael.

Reply by email

Sven Barth
to Mattias Gaertner: Marcos Douglas hat am 29. März 2012 um 13:06 geschrieben: In former Windows versions…
Mattias Gaertner wrote 27 lines
Marcos Douglas hat am 29. März 2012 um 13:06 geschrieben: >[...]> > === output end === > > > > Please note that in "cmd" the following are different: > > > > set FOO=bar > > => "FOO" -> "bar" > > set FOO = bar > > => "FOO " -> " bar" > > set FOO= bar > > => "FOO" -> " bar" > > set FOO =bar > > => "FOO " -> "bar" > > > > Regards, > > Sven > > The application is installed and the system variable is created. The > application and others process should be use this variable just > calling SysUtils.GetEnvironmentVariable. In former Windows versions sometimes you had to logout/login to get the new environment variables. Is this still the case with Windows 7?

At least for "per user" environment variables it should work without. And according to a quick test it works with system ones as well.

Regards,
Sven

Reply by email

Marcos Douglas
to Sven Barth: Then let a FPC program print all passed environment variables as a test: === source begin…
Sven Barth wrote 24 lines
Am 29.03.2012 13:06, schrieb Marcos Douglas: > The application is installed and the system variable is created. The > application and others process should be use this variable just > calling SysUtils.GetEnvironmentVariable. Then let a FPC program print all passed environment variables as a test: === source begin === program envtest; var  i: LongInt; begin  for i := 0 to GetEnvironmentVariableCount do    Writeln(GetEnvironmentString(i)); // Note: this will include "name=value" unlike GetEnvironmentVariable end. === source end ===

I know it works on WinXP but my client uses Win7 and I don't have Win7 at this moment so, somebody can test this, please?

Also - as I already wrote - you can use the Process Explorer ( http://technet.microsoft.com/de-de/sysinternals/bb896653 ) to check whether the application does indeed contain the environment variable.

If the app do not found the environment variable, what I can tell to the user? He do not know this things... the variable was set by installer and the application should be able to use.

Marcos Douglas

Reply by email

Marcos Douglas
to Mattias Gaertner: Marcos Douglas hat am 29. März 2012 um 13:06 geschrieben: In former Windows versions…
Mattias Gaertner wrote 29 lines
Marcos Douglas hat am 29. März 2012 um 13:06 geschrieben: >[...]> > === output end === > > > > Please note that in "cmd" the following are different: > > > > set FOO=bar > >  => "FOO" -> "bar" > > set FOO = bar > >  => "FOO " -> " bar" > > set FOO= bar > >  => "FOO" -> " bar" > > set FOO =bar > >  => "FOO " -> "bar" > > > > Regards, > > Sven > > The application is installed and the system variable is created. The > application and others process should be use this variable just > calling SysUtils.GetEnvironmentVariable. In former Windows versions sometimes you had to logout/login to get the new environment variables. Is this still the case with Windows 7?

Hm... I don't think so but I can't confirm that.

Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas: I know it works on WinXP but my client uses Win7 and I don't have Win7 at this moment so,…
Marcos Douglas wrote 28 lines
On Thu, Mar 29, 2012 at 8:13 AM, Sven Barth wrote: > Am 29.03.2012 13:06, schrieb Marcos Douglas: > >> The application is installed and the system variable is created. The >> application and others process should be use this variable just >> calling SysUtils.GetEnvironmentVariable. > > > Then let a FPC program print all passed environment variables as a test: > > > === source begin === > > program envtest; > > var > i: LongInt; > begin > for i := 0 to GetEnvironmentVariableCount do > Writeln(GetEnvironmentString(i)); // Note: this will include "name=value" > unlike GetEnvironmentVariable > > end. > > === source end === I know it works on WinXP but my client uses Win7 and I don't have Win7 at this moment so, somebody can test this, please?

The point is that for me it works.

Show quoted text 7 lines
> Also - as I already wrote - you can use the Process Explorer ( > http://technet.microsoft.com/de-de/sysinternals/bb896653 ) to check whether > the application does indeed contain the environment variable. If the app do not found the environment variable, what I can tell to the user? He do not know this things... the variable was set by installer and the application should be able to use.

Ok, that might be a problem then...

Regards,
Sven

Reply by email

Marcos Douglas
to Unknown author: He means that you must check using the SET command in a command window. So run - execute…
Show quoted text 56 lines
On Thu, 29 Mar 2012, Marcos Douglas wrote: > On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd > wrote: >> >> Marcos Douglas wrote: >> >>> I know that I have to define the environment variable before or after >>> starting the application or IDE. >>> As I said, works in WinXP... but I had a little problem with a client >>> using Win7 so, I talked about this on lazarus-br list and asked to >>> somebody do the test on Win7 and they said the test did not work so, I >>> wrote here. >> >> >> >> I think the absolutely crucial thing here is to ask what the relationship >> between the session in which the shell/environment variable was defined, >> and >> the FPC program. > > > Nothing. > >> If the variable is set and the program is run from the same prompt, >> provided >> that it's not messed up by extra spaces or by e.g. an interposed >> command.com, then it should work. > > > No. The variable is set using a install program or Windows. > >> In any other case it might work, and it's entirely reasonable to assume >> that >> the extent to which variables are passed between running processes will >> vary >> wildly with OS version. >> >> I suggest the *first* thing to do is to confirm that the variable has >> stuck >> by using the  set  command. After that try running the Pascal program. > > > No command set is used. > The variable has been created in the Windows System Variables. He means that you must check using the SET command in a command window. So run - execute : CMD.exe In the command terminal that opens, type 'SET' (+enter) Your variable should show up in the list of environment variables.

I know I'm crazy because I develop to Win7 but I don't have the Win7 in all machines that I use... sorry about that... but again: I don't have Win7 now and I can't send an application test to the user just to confirm this.
The SET command can work but that means it work using the system variables too?

Please note that under windows 7, there are system environment variables, and user variables.

Because this I always write System Variable and not User Variable.

Show quoted text 5 lines
If the application is installed using user A, but user B runs your program, it is possible that the environment variable is not shown. It depends on how the variable was created by your installer. To check this, the command window can be used.

System Variable, for all users, and I checked the Win7.

The RTL of Free Pascal just calls the Windows API to get the environment variable. No magic is performed.

Yes, I saw the sources, and because this I don't understand what is wrong.

Marcos Douglas

Reply by email

Mark Morgan Lloyd
to Marcos Douglas: On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd Nothing. No. The variable is set using…
Marcos Douglas wrote 32 lines
On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd wrote: > Marcos Douglas wrote: > >> I know that I have to define the environment variable before or after >> starting the application or IDE. >> As I said, works in WinXP... but I had a little problem with a client >> using Win7 so, I talked about this on lazarus-br list and asked to >> somebody do the test on Win7 and they said the test did not work so, I >> wrote here. > > I think the absolutely crucial thing here is to ask what the relationship > between the session in which the shell/environment variable was defined, and > the FPC program. Nothing. > If the variable is set and the program is run from the same prompt, provided > that it's not messed up by extra spaces or by e.g. an interposed > command.com, then it should work. No. The variable is set using a install program or Windows. > In any other case it might work, and it's entirely reasonable to assume that > the extent to which variables are passed between running processes will vary > wildly with OS version. > > I suggest the *first* thing to do is to confirm that the variable has stuck > by using the set command. After that try running the Pascal program. No command set is used. The variable has been created in the Windows System Variables.

In simple English: if you enter the set command, do you see the variable? If not, it's an OS or installer problem.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Marcos Douglas
to Sven Barth: The point is that for me it works. Ok, that might be a problem then... Sven
Sven Barth wrote 38 lines
Am 29.03.2012 13:29, schrieb Marcos Douglas: > On Thu, Mar 29, 2012 at 8:13 AM, Sven Barth >  wrote: >> >> Am 29.03.2012 13:06, schrieb Marcos Douglas: >> >>> The application is installed and the system variable is created. The >>> application and others process should be use this variable just >>> calling SysUtils.GetEnvironmentVariable. >> >> >> >> Then let a FPC program print all passed environment variables as a test: >> >> >> === source begin === >> >> program envtest; >> >> var >>  i: LongInt; >> begin >>  for i := 0 to GetEnvironmentVariableCount do >>    Writeln(GetEnvironmentString(i)); // Note: this will include >> "name=value" >> unlike GetEnvironmentVariable >> >> end. >> >> === source end === > > > I know it works on WinXP but my client uses Win7 and I don't have Win7 > at this moment so, somebody can test this, please? The point is that for me it works.

Have you test on Win7 and worked using FPC 2.6.1? Strange... but thanks.

Show quoted text 12 lines
>> Also - as I already wrote - you can use the Process Explorer ( >> http://technet.microsoft.com/de-de/sysinternals/bb896653 ) to check >> whether >> the application does indeed contain the environment variable. > > > If the app do not found the environment variable, what I can tell to > the user? He do not know this things... the variable was set by > installer and the application should be able to use. Ok, that might be a problem then...

Well, I changed the application to search the correct path when starts, instead of use the System Variable. Works fine but I wanted comment this here because I thought there is something wrong with the GetEnvironmentVariable function.

Marcos Douglas

Reply by email

Marcos Douglas
to Mark Morgan Lloyd: In simple English: if you enter the set command, do you see the variable? If not, it's…
Mark Morgan Lloyd wrote 48 lines
Marcos Douglas wrote: > > On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd > wrote: >> >> Marcos Douglas wrote: >> >>> I know that I have to define the environment variable before or after >>> starting the application or IDE. >>> As I said, works in WinXP... but I had a little problem with a client >>> using Win7 so, I talked about this on lazarus-br list and asked to >>> somebody do the test on Win7 and they said the test did not work so, I >>> wrote here. >> >> >> I think the absolutely crucial thing here is to ask what the relationship >> between the session in which the shell/environment variable was defined, >> and >> the FPC program. > > > Nothing. > >> If the variable is set and the program is run from the same prompt, >> provided >> that it's not messed up by extra spaces or by e.g. an interposed >> command.com, then it should work. > > > No. The variable is set using a install program or Windows. > >> In any other case it might work, and it's entirely reasonable to assume >> that >> the extent to which variables are passed between running processes will >> vary >> wildly with OS version. >> >> I suggest the *first* thing to do is to confirm that the variable has >> stuck >> by using the  set  command. After that try running the Pascal program. > > > No command set is used. > The variable has been created in the Windows System Variables. In simple English: if you enter the  set  command, do you see the variable? If not, it's an OS or installer problem.

Mark,
Thanks for try to help me... but did you read what I wrote about do tests on Win7? The problem happen just Win7 -- WinXP works fine.

Marcos Douglas

Reply by email

Chad Berchek
to Marcos Douglas: I think SysUtils.GetEnvironmentVariable has a problem. I tried to use…

Works fine for me on Windows 7. Here's the Windows version details:

Windows 7 Pro, 64-bit, with Service Pack 1. The "ver" command shows 6.1.7601.

I tested 3 cases:
1. Setting the environment variable using the "set" command in a command line prompt then immediately running the test program.
2. Setting a user-specific environment variable in the System control panel GUI.
3. Setting a machine-wide environment variable in the System control panel GUI.

Note: One thing to keep in mind is that programs get their copy of the environment when they start. So if you add or change a variable after a program has started, that program will likely not see the change until it is restarted, and nor would any child processes it starts. For example if you open a command line and THEN set an environment variable through another program (like the control panel GUI), it will not be visible in that command line or any programs you run from it. You'd have to start a new command line after you add/change your variable. I believe this has been the way programs work since the days of DOS. I.e., they get their copy of the environment block when they first start.

For reference here is the test program, compiled with FPC 2.4.2 on Win XP Pro 64-bit (as I don't actually have FPC on my Win 7 machine). Here is the version output line from the compiler:

Free Pascal Compiler version 2.4.2 [2011/03/08] for i386

and the program:

-----
program getenvtest;
{$mode objfpc}{$H+}
uses
   SysUtils;
begin
   WriteLn(GetEnvironmentVariable('TestVar'));
end.
-----
Marcos Douglas wrote 24 lines
Hi, I think SysUtils.GetEnvironmentVariable has a problem. I tried to use GetEnvironmentVariable on WinXP and Win7. Sometimes works on WinXP, others not. But never worked on Win7. I asked some friends to test on Linux and did not work too. My FPC is 2.6.1 rev 20648 on WinXP. The test: 1- Create a Environment Variable (eg: FOO). 2- Try this: procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(SysUtils.GetEnvironmentVariable('FOO')); end; Marcos Douglas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Marcos Douglas
to Chad Berchek
Chad Berchek wrote 45 lines
Works fine for me on Windows 7. Here's the Windows version details: Windows 7 Pro, 64-bit, with Service Pack 1. The "ver" command shows 6.1.7601. I tested 3 cases: 1. Setting the environment variable using the "set" command in a command line prompt then immediately running the test program. 2. Setting a user-specific environment variable in the System control panel GUI. 3. Setting a machine-wide environment variable in the System control panel GUI. Note: One thing to keep in mind is that programs get their copy of the environment when they start. So if you add or change a variable after a program has started, that program will likely not see the change until it is restarted, and nor would any child processes it starts. For example if you open a command line and THEN set an environment variable through another program (like the control panel GUI), it will not be visible in that command line or any programs you run from it. You'd have to start a new command line after you add/change your variable. I believe this has been the way programs work since the days of DOS. I.e., they get their copy of the environment block when they first start. For reference here is the test program, compiled with FPC 2.4.2 on Win XP Pro 64-bit (as I don't actually have FPC on my Win 7 machine). Here is the version output line from the compiler: Free Pascal Compiler version 2.4.2 [2011/03/08] for i386 and the program: ----- program getenvtest; {$mode objfpc}{$H+} uses  SysUtils; begin  WriteLn(GetEnvironmentVariable('TestVar')); end. -----

Thanks for the test.
We have a little difference: my FPC is 2.6.1 (svn /fixes_2_6). The env variable was added before I start the application, always.

Marcos Douglas

Reply by email

waldo kitty
to Marcos Douglas
Marcos Douglas wrote
Thanks for the test. We have a little difference: my FPC is 2.6.1 (svn /fixes_2_6). The env variable was added before I start the application, always.

and this is from command line (cmd.exe, command.exe or *shell) ??

or in the user or system environment? i'm just trying to keep up ;)

Reply by email

Marcos Douglas
to waldo kitty: and this is from command line (cmd.exe, command.exe or *shell) ?? or in the user or…
waldo kitty wrote 10 lines
On 3/29/2012 21:26, Marcos Douglas wrote: > > Thanks for the test. > We have a little difference: my FPC is 2.6.1 (svn /fixes_2_6). > The env variable was added before I start the application, always. and this is from command line (cmd.exe, command.exe or *shell) ?? or in the user or system environment? i'm just trying to keep up ;)

System environment.

Marcos Douglas

Reply by email