Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I call a korn shell script from perl?

Status
Not open for further replies.

juanmj

Technical User
Nov 13, 2001
5
US
I've tried using the perl system command to call a korn shell script which among other things basically it sets some paths and it takes 2 parameters as input... When I callit manually from a terminal it works fine, but when calling it from a perl script it does not set my paths as desired...

Here is how I call it from my perl script:

system "k-script parm1 parm2";


Any Ideas ???

 
I believe that the system command, or backticks or exec, actually fork a child shell to execute the command. The child gets the environment of the parent perl process(I think), but once the system command is complete, the child ends(dies), and the childs envirnoment dies with it - the parent does not pick up the environment of the child.

Within a Perl program, there are ways of modifying the script's environment - read up on "use lib" - if you have package Mypackage.pm sitting in /tmp, then you can do

use lib "/tmp";
use Mypackage;

to use package Mypackage.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
You can change the environment variables that are made available to something called with system() by modifying the %ENV array, like this to add a directory to the $PATH variable.

$ENV{'PATH'}="$ENV{'PATH'}:/usr/contrib/bin";

Any environment variable can be changed in this way. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top