How to I change my enviroment varables via a perl script. (DOS) 
Author Message
 How to I change my enviroment varables via a perl script. (DOS)

Quote:
>From the FAQ (8):
> I {changed directory, modified my environment} in a perl script. How come
> the change disappeared when I exited the script? How do I get my changes
> to be visible?

> Unix

>     In the strictest sense, it can't be done -- the script executes as a
>     different process from the shell it was started from. Changes to a
>     process are not reflected in its parent, only in its own children
>     created after the change. There is shell magic that may allow you
>     to fake it by eval()ing the script's output in your shell; check
>     out the comp.unix.questions FAQ for details.

Is the answer the same for Dos or windows systems?

Currently I use a convoluted method to achieve this objective, similar to
the answer above.

Instead of running my perl script directly, I call a batch file that calls
the script. The script then emits a second batch file to change the
environment, which is called by the first batch file when the script exits.

I think the above method is messy. What I would prefer to do, is to have
some sort of use directive within a script that would cause envar changes to
persist when the script quits. Is anything like that available?

I think I can see how it might be achieved, but I don't want to re-invent
the wheel if the code already exists.

Thanks in advance.

--
David Pottage



Sat, 23 Aug 2003 20:20:05 GMT  
 How to I change my enviroment varables via a perl script. (DOS)
: >From the FAQ (8):

: > I {changed directory, modified my environment} in a perl script. How come
: > the change disappeared when I exited the script? How do I get my changes
: > to be visible?
: >
: > Unix
: >
: >     In the strictest sense, it can't be done -- the script executes as a
: >     different process from the shell it was started from. Changes to a
: >     process are not reflected in its parent, only in its own children
: >     created after the change. There is shell magic that may allow you
: >     to fake it by eval()ing the script's output in your shell; check
: >     out the comp.unix.questions FAQ for details.

: Is the answer the same for Dos or windows systems?

: Currently I use a convoluted method to achieve this objective, similar to
: the answer above.

: Instead of running my perl script directly, I call a batch file that calls
: the script. The script then emits a second batch file to change the
: environment, which is called by the first batch file when the script exits.

I believe that is the only method on NT, though I haven't tried very hard
to do it any other way.

The initial environment on NT is stored via the registry, so perhaps the
registry has some hook to change the running environment.

In 16 bit DOS/Windows there were various undocumented but well known
methods to set the callers environment.  At least some of the techniques
still work on Windows 95.  In one technique uses the fact that the PSP
associated with the program has a pointer back to the caller's PSP, which
points to the environment strings.  I do not recall how how a win32
program find's it's DOS PSP, though I know it can be done (on 95/98, not
NT).

On NT you might be able to invoke COMMAND.COM as the shell and get at its
environment in a similar way, though I wouldn't count on it.



Wed, 27 Aug 2003 01:25:30 GMT  
 How to I change my enviroment varables via a perl script. (DOS)

Quote:

>>From the FAQ (8):
>> I {changed directory, modified my environment} in a perl script. How come
>> the change disappeared when I exited the script? How do I get my changes
>> to be visible?

>> Unix

>>     In the strictest sense, it can't be done -- the script executes as a
>>     different process from the shell it was started from. Changes to a
>>     process are not reflected in its parent, only in its own children
>>     created after the change. There is shell magic that may allow you
>>     to fake it by eval()ing the script's output in your shell; check
>>     out the comp.unix.questions FAQ for details.
> Is the answer the same for Dos or windows systems?

Pretty much.

Quote:
> Currently I use a convoluted method to achieve this objective, similar to
> the answer above.
> Instead of running my perl script directly, I call a batch file that calls
> the script. The script then emits a second batch file to change the
> environment, which is called by the first batch file when the script exits.

This is how I've done things on both Unixy and DOSy platforms for
a long time, not only in Perl but in QuickBASIC, C, TurboPascal,
and Ada as well.

Quote:
> I think the above method is messy. What I would prefer to do, is to have
> some sort of use directive within a script that would cause envar changes to
> persist when the script quits. Is anything like that available?

Messy requirements sometimes require messy implementations.

Quote:
> I think I can see how it might be achieved, but I don't want to re-invent
> the wheel if the code already exists.

If you change your shell so that children can pass environment
changes back to the parent, then that would also be messy
(although maybe not quite so much so) and have the effects of
being highly unintuitive and unportable, too.

Chris

--
Christopher E. Stith
Disclaimer: Actual product may not resemble picture in ad in any way.



Wed, 27 Aug 2003 04:34:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. FIB Compilation error

2. Interbase on Windows NT Alpha?

3. Changing Form Input via Perl Script/Mail Script

4. Is there a dos htm enviroment for perl ?

5. perl script to change unix passwords via http

6. Change password in /etc/shadow via script

7. Changing password for given user in Netscape LDAP server via CGI script

8. Change password via cgi script

9. Setting an Enviroment Variable in a Web Perl script

10. Perl Scripts from within Perl Scripts called via DBI

11. Q: Changing IP address via perl

12. send enviroment variables to a script..

 

 
Powered by phpBB® Forum Software