Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 8th, 2013, 06:05 PM
kochaloch's Avatar
kochaloch kochaloch is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 40 kochaloch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 34 m 15 sec
Reputation Power: 6
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!!!

Reply With Quote
  #2  
Old January 8th, 2013, 09:07 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 188 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 4 m 54 sec
Reputation 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..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Run two sh script's from perl

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap