By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,660 Members | 1,299 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,660 IT Pros & Developers. It's quick & easy.

Execute script2 from script1 and transfer two arguments to script2

P: 5
Hello everybody

need help:
How do i execute script2 from script1 and transfer two things
$first and $second from script1 to script2
Need to do it in unix enviroment and windows also(cmd).

There is a command :system()
i used it as follows:
Expand|Select|Wrap|Line Numbers
  1. #script1;
  2. system ("/just/an/example/script2 $first  $second  ");
  3.  
Did not see any response to this command,
Please help
Thanks a lot
Nov 4 '08 #1
Share this Question
Share on Google+
4 Replies


P: 62
Try them:

Expand|Select|Wrap|Line Numbers
  1.  open(PIPE,"|perl -w script2.pl"); 
  2.  print PIPE "$omething";
  3.  close(PIPE);
if so in script2 must wait for data <>;

when use pipeing from shell, the output of script1 is the input of script2.

Expand|Select|Wrap|Line Numbers
  1. perl script1.pl | perl script2.pl 
Nov 4 '08 #2

P: 5
Hello again


The problem with what you suggested is that script1
does a lot of things and among those things it is printing out
some results.So how exectly can i extract that certain data that is needed for script2 from script1.
furthermore i need to transfer two arguments.
Isn't <> waits for one variable?

Thanks again
Nov 6 '08 #3

nithinpes
Expert 100+
P: 410
If I understood your requirement correctly, all you want to do is to execute script2 from script1 and pass arguments to script2 from script1.
If that is so, you have to handle these arguments(@ARGV) properly in script2. For example,
script1.pl
Expand|Select|Wrap|Line Numbers
  1. #script1
  2. $first = "Hi";
  3. $second= "Hello";
  4. system ("D:\\script2.pl $first $second "); 
  5.  
and
script2.pl
Expand|Select|Wrap|Line Numbers
  1. #script2
  2. my ($one,$two) = @ARGV; 
  3. print "first: $one\n";
  4. print "second: $two\n";
  5.  
would print:
Expand|Select|Wrap|Line Numbers
  1. first: Hi
  2. second: Hello
  3.  
Nov 6 '08 #4

P: 5
Thanks for the reply.

At the begining it did not worked becuase i forgot somthing:
Expand|Select|Wrap|Line Numbers
  1. (system ("perl /path/sc2.pl $first $second ")== 0) or die "myprogram failed ($?): $!";
  2.  
I forgot the "perl" at the command, that why it could not execute the second script.
Stupid, isn't it

Thanks a lot
Nov 6 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.