For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > April 2007 > $ENV HOME on windows









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author $ENV HOME on windows
Bob

2007-04-22, 10:01 pm

I apologise for the basic question, but I am using perl on windows for
the first time (after about 20 years using it on unix...) and the
problem does not make sense to me. Perl (active state) complaints that
the value is not initialized. Why in heaven?

#!/usr/bin/perl -w
use strict;
use diagnostics;
print $ENV{HOME};

Dr.Ruud

2007-04-22, 10:01 pm

Bob schreef:
> I apologise for the basic question, but I am using perl on windows for
> the first time (after about 20 years using it on unix...) and the
> problem does not make sense to me. Perl (active state) complaints that
> the value is not initialized. Why in heaven?
>
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
> print $ENV{HOME};


Do a `set` in a CMD shell console window, or use perl:
perl -wle "print qq{$_=$ENV{$_}} for sort keys %ENV"
(which will show the keys in allcaps)
and you'll see something like

HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Username


The concatenation can be used as HOME:

BEGIN {
if ( substr ( $^O, 0, 5 ) eq q{MSWin} ) {
if ( $ENV{HOME} ) {
# leave as is
}
elsif ( $ENV{USERPROFILE} ) {
$ENV{HOME} = $ENV{USERPROFILE};
}
elsif ( $ENV{HOMEDRIVE} and $ENV{HOMEPATH} ) {
$ENV{HOME} = $ENV{HOMEDRIVE} . $SENV{HOMEPATH};
}
else {
$ENV{HOME} = '.';
} } }

There are also modules on the cpan that do something alike.

--
Affijn, Ruud

"Gewoon is een tijger."

Peter Scott

2007-04-23, 8:02 am

On Sun, 22 Apr 2007 09:19:35 -0700, Bob wrote:
> I apologise for the basic question, but I am using perl on windows for
> the first time (after about 20 years using it on unix...) and the
> problem does not make sense to me. Perl (active state) complaints that
> the value is not initialized. Why in heaven?


See
http://search.cpan.org/~rkobes/File...omeDir/Win32.pm

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Matthew X. Economou

2007-04-25, 7:02 pm

>>>>> "Ruud" == Ruud <rvtol+news@isolution.nl> writes:

Ruud> HOMEDRIVE=C:
Ruud> HOMEPATH=\Documents and Settings\Username

Ruud> The concatenation can be used as HOME:

I wrote a small Windows Installer (MSI) package that adds an entry
"HOME" (with the value "%HOMEDRIVE%%HOMEPATH%") to the user's
profile. I pushed the package to all domain users via a group policy
object (under User Configuration, Software Settings, Software
installation; made it an assigned application). The original poster
should be able to do something similar using Wise for Windows
Installer (expensive but easy) or WiX (free but difficult).

Best wishes,
Matthew

--
"Rogues are very keen in their profession, and know already much more
than we can teach them respecting their several kinds of roguery."
- A. C. Hobbs in _Locks and Safes_ (1853)
Ilya Zakharevich

2007-04-25, 7:02 pm

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Dr.Ruud
<rvtol+news@isolution.nl>], who wrote in article <f0gb3i.1do.1@news.isolution.nl>:

> HOMEDRIVE=C:
> HOMEPATH=\Documents and Settings\Username


What puzzles me deep is why Perl on Windows is not faking $ENV{HOME}
if $ENV{HOMEPATH} and $ENV{HOMEPATH} are both present... I think this
would remove at least 10-20% of porting problems...

Yours,
Ilya
Petr Vileta

2007-04-25, 10:01 pm

"Ilya Zakharevich" <nospam-abuse@ilyaz.org> píše v diskusním příspěvku
news:f0opmc$27r$1@agate.berkeley.edu...
> What puzzles me deep is why Perl on Windows is not faking $ENV{HOME}
> if $ENV{HOMEPATH} and $ENV{HOMEPATH} are both present... I think this
> would remove at least 10-20% of porting problems...
>

From which hell get you HOME variable? :-)
On my WinXP-Pro this environment variable is not.

Run cmd.exe

C:\>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Petr\Dataap~1
CLIENTNAME=Console
COMMANDER_PATH=D:\totalcmd
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=PETR
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Petr
LOGONSERVER=\\PETR
NUMBER_OF_PROCESSORS=1
OPENSSL_CONF=C:\OpenSSL\bin\openssl.cnf
OS=Windows_NT
Path=D:\Perl\bin\;D:\php;C:\WINDOWS\syst
em32;C:\WINDOWS;C:\WINDOWS\System32\Wbem

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.pyo;.pyc;.pyw;.py
PERL5LIB=E:\Progra~1\PDK60\lib\
PERLDB_OPTS=RemotePort=127.0.0.1:2000
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0401
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=L:\Temp
TMP=L:\Temp
USERDOMAIN=[cenzored]
USERNAME=Petr
USERPROFILE=C:\Documents and Settings\Petr
windir=C:\WINDOWS
C:\>

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)


Anerhader0

2007-04-26, 6:58 am

http://Angelina-Jolie-doing-it.info...hp?movie=148803
anno4000@radom.zrz.tu-berlin.de

2007-04-26, 7:03 pm

Petr Vileta <stoupa@practisoft.cz> wrote in comp.lang.perl.misc:
> "Ilya Zakharevich" <nospam-abuse@ilyaz.org> píše v diskusním příspěvku
> news:f0opmc$27r$1@agate.berkeley.edu...

One of these should be $ENV{HOMEDRIVE}
[color=darkred]
> From which hell get you HOME variable? :-)


The suggestion is for Perl to *fake* it in %ENV, deriving the value
from $ENV{HOMEDRIVE} and $ENV{HOMEPATH}. The system environment
doesn't have to have HOME for that.

Anno
A. Sinan Unur

2007-04-26, 7:03 pm

anno4000@radom.zrz.tu-berlin.de wrote in news:59b8c2F2ir6nuU2
@mid.dfncis.de:

> Petr Vileta <stoupa@practisoft.cz> wrote in comp.lang.perl.misc:
příspěvku[color=darkred]
{HOME}[color=darkred]
this[color=darkred]
>
> One of these should be $ENV{HOMEDRIVE}
>
>
> The suggestion is for Perl to *fake* it in %ENV, deriving the value
> from $ENV{HOMEDRIVE} and $ENV{HOMEPATH}. The system environment
> doesn't have to have HOME for that.


Which might be a problem for those of us who create a D:\Home and move
users' 'My Documents' folders to directories under D:\Home\<userid> and
add a HOME variable to each user's environment. I am assuming such
problems can be avoided by checking for the existence of of $ENV{HOME}
before faking it. However, this means that the check and the decision as
to whether to fake $ENV{HOME} should not be done at install time but
each time a script is run.

I still do think it is a good idea to fake $ENV{HOME} using
$ENV{HOMEDRIVE} and $ENV{HOMEPATH}.

Sinan

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmis...guidelines.html

Ilya Zakharevich

2007-04-26, 7:03 pm

[A complimentary Cc of this posting was sent to
A. Sinan Unur
<1usa@llenroc.ude.invalid>], who wrote in article <Xns991E5FEC1439Casu1cornelledu@127.0.0.1>:
> {HOME}
> this



Yeah, thanks.
[color=darkred]
[color=darkred]
> Which might be a problem for those of us who create a D:\Home and move
> users' 'My Documents' folders to directories under D:\Home\<userid> and
> add a HOME variable to each user's environment. I am assuming such
> problems can be avoided by checking for the existence of of $ENV{HOME}
> before faking it.


Hmm, I thought that this would be clear without saying... Sorry!

> However, this means that the check and the decision as
> to whether to fake $ENV{HOME} should not be done at install time but
> each time a script is run.


Each time the interpreter starts.

Hope this helps,
Ilya
A. Sinan Unur

2007-04-26, 7:03 pm

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in
news:f0qgl5$1893$1@agate.berkeley.edu:

> [A complimentary Cc of this posting was sent to
> A. Sinan Unur
> <1usa@llenroc.ude.invalid>], who wrote in article
> <Xns991E5FEC1439Casu1cornelledu@127.0.0.1>:

....
>
> Hmm, I thought that this would be clear without saying... Sorry!
>
>
> Each time the interpreter starts.


Looks like my post was a little redundant but thanks for the
acknowledgement.

Sinan

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmis...guidelines.html

Michele Dondi

2007-04-28, 8:01 am

On Wed, 25 Apr 2007 23:53:48 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:

>What puzzles me deep is why Perl on Windows is not faking $ENV{HOME}
>if $ENV{HOMEPATH} and $ENV{HOMEPATH} are both present... I think this


I bet that if $ENV{HOMEPATH} is defined, then so is $ENV{HOMEPATH}!
;-)


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com