Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Reading and setting the environment from a shell script for the calling program

by robby123 (Initiate)
on Sep 01, 2004 at 13:37 UTC ( [id://387513]=perlquestion: print w/replies, xml ) Need Help??

robby123 has asked for the wisdom of the Perl Monks concerning the following question:

Im new to perl... we have a shell script(env_set.sh) which basically sets some environment variables,I need to call this shell script inside my perl program in such a way that changes made by the shell script should be reflected when the control comes back to the perl program (something like what we do on the command line ( . ./env_set.sh ) we used to do this by calling the env_set.sh inside another shell program main.sh this way (. env_set.sh). Now we need to rewrite the main.sh in perl but wanted to reuse the env_set.sh ksh script. is there a way to achive this. Thanks in advance Robby

20040903 Edit by castaway: Changed title from 'Hi'

Replies are listed 'Best First'.
Re: Reading and setting the environment from a shell script for the calling program
by Corion (Patriarch) on Sep 01, 2004 at 13:48 UTC

    Hello and welcome to the monastery, robby123!

    Using Super Search, I quickly found this excellent node by tilly which should solve your problem.

    Please consider better titles for your nodes instead of stream-of-consciousness, as many people will skip nodes with badly chosen titles. Also, pasting your question into the chatterbox ("CB") isn't helpfull either, as many people will see your node either in the Seekers of Perl Wisdom section or on Newest Nodes.

Re: Reading and setting the environment from a shell script for the calling program
by herveus (Prior) on Sep 01, 2004 at 13:52 UTC
    Howdy!

    The child process cannot change the parent process's environment. Period. Stop. End of story.

    On the other hand, if the child process diddles its environment and concludes by running 'env', the parent can capture that output and use it (or whatever subset it cares to take) to update its own environment.

    See Re: UNIX environment setup via perl for my take on this...

    yours,
    Michael
Re: Reading and setting the environment from a shell script for the calling program
by gman (Friar) on Sep 01, 2004 at 13:49 UTC
    Without seeing the script, would it be to much
    to set the environment variables in your perl script
    ie. $ENV{'JAVA_HOME'} = ''
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://387513]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-03-19 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found