473,505 Members | 16,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control one script from the other.

3 New Member
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 1053
nithinpes
410 Recognized Expert Contributor
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
krieger
3 New Member
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

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

Similar topics

0
1478
by: Mircea Pleteriu | last post by:
Hi all, I have created a .NET Windows control with c#. I have placed the control on a HTML page within the OBJECT element. Everything works fine up to now. Now, I wanna implement the...
11
4960
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div,...
0
1934
by: Ron Vecchi | last post by:
Hello, Through using this and many other Microsoft dotnet newsgroups I have been pointed towards many helpful open source projects and articles that have helped a great deal in my studies as...
7
7715
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
6
14673
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
15
4713
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
5
3565
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
7
1568
by: Hans Merkl | last post by:
Hi, Can anybody recommend a combo box control (textfield + dropdown list) for ASP.NET? I have looked at some products and it seems they all have some problems. I haven't yet found a combo box...
1
7766
by: avp | last post by:
Hi, We have an ASP.NET 2.0 (C#) application that has a web form with a CheckBoxList control and a CustomValidator control. The CustomValidator control is used to validate that at least one...
2
4804
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.