#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    41
    Rep Power
    7

    Run two sh script's from perl


    Hello,

    so the issue is I have a shell script I need to execute from a Perl script, the problem is I have to run another script to load environmental variable's so when I run it manually it looks like:

    ./run_env.sh script.sh

    I have tried numerous things(system, exec, backticks) and can't seem to get this to work. I've tried running a single script like this and it does work.

    system ("sh", "test.sh");

    The following does not work

    system ("sh", "run_env.sh", "script.sh");

    Any help appreciated.

    Thanks!!!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    225
    Rep Power
    41
    If i understand what you trying to do, This is one way:
    Code:
    use strict;
    use warnings;
    
    my @cmd_list = ( 'echo $ORACLE_SID', 'ORACLE_SID=TEST;export ORACLE_SID', 'echo A', 'echo B', 'echo $ORACLE_SID' );
    my $cmd;
    my $shell_cmd;
    my $child_pid;
    
    $child_pid = open( $shell_cmd, '|-', '/usr/bin/ksh' ) or die "Error opening shell process: $!\n";
    
    foreach $cmd ( @cmd_list ) {
      print $shell_cmd "$cmd\n";
    }
    print $shell_cmd "exit\n";
    close $shell_cmd;
    waitpid( $child_pid, 0 );
    
    print "Finished..\n";
    
    
    $ test_shell.pl
    QINTER
    A
    B
    TEST
    Finished..

IMN logo majestic logo threadwatch logo seochat tools logo