467,202 Members | 1,114 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,202 developers. It's quick & easy.

Execute script2 from script1 and transfer two arguments to script2

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
  • viewed: 1395
Share:
4 Replies
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
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 256MB
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
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.

Similar topics

4 posts views Thread by smarty | last post: by
6 posts views Thread by Sam | last post: by
4 posts views Thread by ewolfman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.