469,307 Members | 2,437 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Control one script from the other.

I have two scripts:
per4.pl
Expand|Select|Wrap|Line Numbers
  1. @food = ("pear", "plum", "egg", "apple");
  2. $TableLength = $#food;
  3. print $TableLength;
  4. for($i = 0; $i < $TableLength; ++$i){
  5.     print "$food[$i]\n";
  6. }
  7. do{
  8.     print "Password?";
  9.     $a = <STDIN>;
  10.     chop $a;
  11. }
  12. while ($a ne "fred");
The other perl5.pl

Expand|Select|Wrap|Line Numbers
  1. $FileName = "perl4.pl";
  2. system $FileName;
  3.  
  4. while($Line ne "Password?"){
  5.     $Line = <STDIN>;
  6.     if($Line eq "Password?"){
  7.          print STDOUT "fred"
  8.        }
  9.        chop $Line;
  10. }
My intention is that when I got question about password from perl4 perl5 should set that and both should finish. Can anybody help me with this task??

Regards
krieger
Feb 29 '08 #1
2 1006
nithinpes
410 Expert 256MB
If you want to perl4.pl to take password from perl5.pl, then you should call perl5.pl within perl4.pl rather than calling perl4.pl from perl5.pl.
You have tried to capture line containing "Password" and pass "fred" to STDOUT, though it is incorrect. The actual flow is that system command will be executed first(perl4.pl will execute first) before getting to while loop.
I would suggest you to try the following script if your objective is just to set password from perl5.pl

perl4.pl
Expand|Select|Wrap|Line Numbers
  1. $FileName = "perl5.pl";
  2.  
  3. @food = ("pear", "plum", "egg", "apple");
  4. $TableLength = $#food;
  5. print $TableLength;
  6. for($i = 0; $i < $TableLength; ++$i){
  7.     print "$food[$i]\n";
  8. }
  9. do{
  10.     print "Password?\n";
  11.     $a = `perl $FileName`;  # get the output from perl5.pl
  12.     $a eq "fred" or $a=<STDIN>; ## take STDIN if $a is not "fred"
  13.     chomp $a;
  14.  
  15. }
  16. while ($a ne "fred");
  17.  

perl5.pl
Expand|Select|Wrap|Line Numbers
  1. print "fred";  ##pass "fred" or write your code
  2.  
I am using reverse quote instead of system command because, system() will return 0 if the command executed or null if it fails.
Mar 4 '08 #2
If you want to perl4.pl to take password from perl5.pl, then you should call perl5.pl within perl4.pl rather than calling perl4.pl from perl5.pl.
You have tried to capture line containing "Password" and pass "fred" to STDOUT, though it is incorrect. The actual flow is that system command will be executed first(perl4.pl will execute first) before getting to while loop.
I would suggest you to try the following script if your objective is just to set password from perl5.pl

perl4.pl
Expand|Select|Wrap|Line Numbers
  1. $FileName = "perl5.pl";
  2.  
  3. @food = ("pear", "plum", "egg", "apple");
  4. $TableLength = $#food;
  5. print $TableLength;
  6. for($i = 0; $i < $TableLength; ++$i){
  7.     print "$food[$i]\n";
  8. }
  9. do{
  10.     print "Password?\n";
  11.     $a = `perl $FileName`;  # get the output from perl5.pl
  12.     $a eq "fred" or $a=<STDIN>; ## take STDIN if $a is not "fred"
  13.     chomp $a;
  14.  
  15. }
  16. while ($a ne "fred");
  17.  

perl5.pl
Expand|Select|Wrap|Line Numbers
  1. print "fred";  ##pass "fred" or write your code
  2.  
I am using reverse quote instead of system command because, system() will return 0 if the command executed or null if it fails.
Hi
The problem is that I will have more interaction between perl5 and perl4, I gave those files only as example. I need to execute perl4 from perl5. In real scripts I cannot change perl4, it is built in a System.
Mar 19 '08 #3

Post your reply

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

Similar topics

reply views Thread by Mircea Pleteriu | last post: by
11 posts views Thread by trinitypete | last post: by
reply views Thread by Ron Vecchi | last post: by
7 posts views Thread by moondaddy | last post: by
6 posts views Thread by Selden McCabe | last post: by
5 posts views Thread by serge calderara | last post: by
7 posts views Thread by Hans Merkl | last post: by
2 posts views Thread by rn5a | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.