Click here to get back home

Using System to read mixed cased environment variables on Windows

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Using System to read mixed cased environment variables on Windows Thierry 06-27-2008
Posted by Thierry on June 27, 2008, 2:00 pm
Please log in for more thread options
On Windows XP Pro 32 bit, if I want to output environment variables
PYTHON or ProgramFiles, I use the set command which output the
following:

C:\set PYTHON
PYTHON=C:\Python24\python.exe
C:\set ProgramFiles
ProgramFiles=C:\Program Files

If I used Perl 5.003_07 and use the system subroutine to show the
environment variables, I get the following. Perl script is:

system("set PYTHON");
system("set ProgramFiles");

Output is:
PYTHON=C:\Python24\python.exe
PROGRAMFILES=C:\Program Files

You'll notice that through system, the environment variable
ProgramFiles is all in upper case. Is there a way to preserve the
mixed case of the environment variable through system(...)?

Posted by Ron Bergin on June 27, 2008, 4:20 pm
Please log in for more thread options
> On Windows XP Pro 32 bit, if I want to output environment variables
> PYTHON or ProgramFiles, I use the set command which output the
> following:
>
> C:\set PYTHON
> PYTHON=C:\Python24\python.exe
> C:\set ProgramFiles
> ProgramFiles=C:\Program Files
>
> If I used Perl 5.003_07

That's a fairly old version. You should upgrade to at least 5.8

> and use the system subroutine to show the
> environment variables, I get the following. Perl script is:
>
> system("set PYTHON");
> system("set ProgramFiles");
>
There's no reason to use a system call. Your environment variables
are already stored in the %ENV hash.

print $ENV;

Posted by sisyphus on June 28, 2008, 1:38 am
Please log in for more thread options
> On Windows XP Pro 32 bit, if I want to output environment variables
> PYTHON or ProgramFiles, I use the set command which output the
> following:
>
> C:\set PYTHON
> PYTHON=3DC:\Python24\python.exe
> C:\set ProgramFiles
> ProgramFiles=3DC:\Program Files
>
> If I used Perl 5.003_07 and use the system subroutine to show the
> environment variables, I get the following. =A0Perl script is:
>
> system("set PYTHON");
> system("set ProgramFiles");
>
> Output is:
> PYTHON=3DC:\Python24\python.exe
> PROGRAMFILES=3DC:\Program Files
>
> You'll notice that through system, the environment variable
> ProgramFiles is all in upper case. =A0Is there a way to preserve the
> mixed case of the environment variable through system(...)?

I find that case is preserved with perl 5.6.2, 5.8.8 and 5.10.0:

C:\>set MyTest=3DC:\MyTest

C:\>set MyTest
MyTest=3DC:\MyTest

C:\CVS>perl -e "system(\"set MyTest\")"
MyTest=3DC:\MyTest

C:\CVS>set MITEST=3DC:\MiTest

C:\CVS>perl -e "system(\"set MiTest\")"
MITEST=3DC:\MiTest

Not quite sure why you get the behaviour you reported ... perhaps it
is just that antiquated version of perl you're running. I guess you
could update your perl and see if the behaviour changes. (Though as
Ron Bergin has already indicated, there are better ways of accessing
the environment variables anyway.)

Cheers,
Rob

Similar ThreadsPosted
Evaluating environment variables June 14, 2006, 5:49 pm
persistent environment variables December 7, 2006, 8:02 pm
how do I access ksh environment array variables in perl? March 24, 2005, 11:24 am
Environment variables in Excel started from Win32::OLE February 15, 2007, 2:32 pm
which file, regestry, environment variables do perl install August 8, 2006, 10:33 am
how to install/use MP3::Tag in Windows environment? February 6, 2007, 6:57 pm
Install Perl on windows 2000 PRO environment March 18, 2007, 9:28 am
Read Variables from include file December 2, 2006, 4:18 pm
How do I read a GZipped UTF-8 file from Perl on Windows? May 29, 2007, 4:24 pm
Formatting ASCII to be read by Windows NotePad July 3, 2008, 5:02 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap