[Israel.pm] Query regarding executing a shell script in perl
Omer Zak
omerz at actcom.co.il
Mon Feb 14 02:29:12 PST 2005
On Mon, 2005-02-14 at 12:22 +0200, Vijay Goutham wrote:
> Hi All,
> I have a perl process. The perl process need to do the following,
>
> a. Execute a shell script (ksh) which sets some environment variables
> (E.g. the shell script contains a set of export statements like,
> export CLASS=10
> export ROOM=4
> etc..
> )
The shell script is executed in a sub-process (a process of its own).
So none of the changes to the values of the environment variables set in
the script are visible.
> b. A set of perl functions which uses these environment variables
> (CLASS, ROOM).
> (E.g. print $ENV{'CLASS'}; )
>
> Now the problem i face is,
>
> I call the shell script (say set_env), using either
>
> i) system("setenv"); (or)
> ii) `setenv` (using backtick)
>
> But the issue is, after executing the system (or `setenv`) the
> environment variables are getting lost.
>
>
> Is there anyway of executing the setenv script and ensure that the
> variables are set in the current shell, so that my perl functions can
> use it?
Possible solutions:
1. Invoke your Perl script from the shell script. The Perl script will
execute in a sub-process of the shell script and inherit its environment
variable values.
2. Set the environment variables by setting $ENV inside the Perl script.
3. Interpret the shell script inside the Perl script i.e. have the Perl
script read the shell script line by line, find which environment
variable+value it wants to set and set the environment as in (2).
4. Write an easily-parsed file listing the environment variables and
desired values and have the Perl script read and parse it and set the
environment variables as in (3).
--- Omer
--
My own blog is at http://www.livejournal.com/users/tddpirate/
My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html
More information about the Perl
mailing list