[fpc-pascal] environmentstrings in windows

Vincent Snijders vsnijders at quicknet.nl
Thu Dec 14 19:41:46 CET 2006


Michael Van Canneyt schreef:
> 
> On Thu, 14 Dec 2006, Vincent Snijders wrote:
> 
>> Consider the following program:
>>
>> {$mode objfpc}{$H+}
>>
>> uses
>>   SysUtils;
>>
>> var
>>   i: integer;
>>   s: string;
>>
>> begin
>>   i := GetEnvironmentVariableCount;
>>   writeln('VariableCount: ',i);
>>   s := GetEnvironmentString(1);
>>   writeln('Variable 1: ', s);
>>   s := GetEnvironmentString(2);
>>   writeln('Variable 2: ', s);
>>   s := GetEnvironmentVariable('=D:');
>>   writeln('Variable 1: ', s);
>> end.
>>
>> If I run this from a command prompt on my windows 2000 computer it gives the
>> following output:
>> VariableCount: 43
>> Variable 1: =D:=D:\lazarus\bugs\7699
>> Variable 2: =ExitCode=00000000
>> Variable 1:
>>
>> The first two envrionment string are special, in the sense that their name
>> start with a =.
>>
>> but if ask for the value of the environment variable '=D:', it returns the
>> empty string.
>>
>> I am wrestling a bit with how to interprete this. Should I consider these
>> variable as special and hidden and ignore them?
>> Or should code parsing environmentstrings be able to handle variables with a
>> '=' on the first position?
> 
> IMHO, you should not be allowed to have a = in the name of an environment
> variable at all. Since obviously you can in Windows, this is a problem which
> will need fixing somehow. 
> I'm pretty sure you can't do this in Linux (I get an illegal variable name error).

In windows it doesn't seem to be allowed either:
C:\lazarus>set =test=p
De syntaxis van de opdracht is onjuist.

> So code relying on this will not be cross-platform.

My problem is code relying in the fact that GetEnvironmentString(1) 
doesn't return strings that start with '='. Will you fix that? Or must 
code using GetEnvironmentString be aware that on some platforms these 
strings can start with =.

Vincent



More information about the fpc-pascal mailing list