Setting ENV varibles by calling a shell script within a perl program

From: ad (as_at_no-span.org)
Date: 05/29/04


Date: Sat, 29 May 2004 11:55:41 -0400


I need to make some system calls to other programs from a perl program
and those programs that are being called have some environment
variable dependencies that are set by a shell script program. So I
have to call this shell script to set up (export bunch of variables)
environment variables so that the other program that I call can run
fine.

If all possible, I am trying to avoid writing another shell program
that call the other shell program prior to my perl program since I
have lots of variable combination that my perl program can run with
and do not want to have all the variable validated with this extra
shell program so that it can call my perl program.

In the following example, I tried both "system" and "``" (backtricks)
but none of them worked.

---- Shell Program ------------
#!/bin/sh

export T1=test1
export T2=test2
export T3=test3
export T4=test4
---- End Of Shell Program -----

----- My Test Perl Program ----
#!/usr/bin/perl

use warnings;
use strict;

#system(". ./myShell.sh"); # Tried both
`. ./myShell.sh`;

print "T1 = $ENV{T1}\n"; # Prints blank
print "T2 = $ENV{T2}\n"; # Prints blank
print "T3 = $ENV{T3}\n"; # Prints blank
print "T4 = $ENV{T4}\n"; # Prints blank
----- End Of Perl Program ----
 
Thanks for the help and suggestions in advance.



Relevant Pages

  • Re: [GCC] A couple of success report
    ... from Paul Smedley's build environment. ... There's also a Perl program for converting MIDI files to Mup file ... Paul, do you have some good news or did I ... I'd like to try and make an EPM extension for Mup, ...
    (comp.os.os2.programmer.porting)
  • Re: exit perl script and cd in bash?
    ... > It is very easy to change the directory from inside a Perl program ... A child process cannot change its parent's environment. ... the parent is a shell, ... An example of COMMAND would be ssh-agent, ...
    (perl.beginners)
  • RE: environment variable
    ... will execute in a sub shell of your perl program. ... how can i export a variable from program perl to shell script through ... intended recipient, please be aware that any disclosure, copying, distribution ... sender of the delivery error by replying to this message, or notify us by ...
    (perl.dbi.users)
  • Re: process control
    ... Neither changes the environment of your perl program in any way ... > until the exports are done above. ... > command would pause until the process was done, ...
    (comp.lang.perl.misc)
  • Re: ping Purl Gurl? Beginner Level Perl
    ... a Perl program which is also less scary. ... these characters, which made for a more interesting educational ... A couple of blank lines appeared in my terminal window, ... that appropriate reconfiguring of my environment would produce ...
    (alt.usage.english)