Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 ( #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'

Comment on Reading and setting the environment from a shell script for the calling program
Re: Reading and setting the environment from a shell script for the calling program
by Corion (Pope) 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 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'} = ''
Re: Reading and setting the environment from a shell script for the calling program
by herveus (Parson) 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 doowah2004 (Monk) on Sep 01, 2004 at 20:33 UTC
    Why not make a system call?

    sytstem("./env_set.sh");

    Cameron
      Because it won't work. That will launch a child process that will set some environment variables and then exit without affecting the parent at all. herveus's reply offers a good solution.

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-09-18 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (109 votes), past polls