?
Solved

Debug plain text input

Posted on 2007-08-03
2
Medium Priority
?
215 Views
Last Modified: 2010-03-05
My script's purpose is to perform .NET functions on a PC client, and it talks back and forth using plain text:
 
a) The script prints plain text, which is intercepted by the client and tells the client which .NET operations to perform (this part is working great).

b) The Windows client (basically a glorified telnet client) sends responses in plain text back to the perl script (with perhaps a CR/LF after each line of text - maybe this is the problem)

The only line that is giving me trouble is the one exiting the loop:

       last if $text eq '3Click,MyForm.button1';

The script exits correctly if i manually run it from the # prompt and type:

       3Click,MyForm.button1

followed by pressing the ENTER key.

The problem is the script does not end when my client sends this text.  Are there alternatives to chomp that I should be using?  To debug, is there a way I can dump the value of $text into a file during each pass through the loop, so I can see what text the script is receiving?  Or is my syntax just inappropriate for the application?

The script:

   #!/usr/bin/perl                                          
                                                         
   # Enter TrueGUI mode:                                    
   print "\$\$EnterTrueGuiMode\$\$\n";                      
                                                         
   # Load the set of Windows Forms we created with Visual Studio:        
   print "{ TrueGui.LoadAssembly(`WindowsApplication1`) }\n";
                                                         
   # Create an instance of Form1 calling it "MyForm"        
   print "{ MyForm = New WindowsApplication1.Form1() }\n";  
                                                         
   # Show MyForm                                            
   print "{ MyForm.Show() }\n";                              
                                                         
   while(1) {                                                
      $text=<STDIN>;                                        
      chomp($text);                                          
      last if $text eq '3Click,MyForm.button1';              
   }                                                        
                                                         
   # end of script                                          

Thanks,
Andrew
0
Comment
Question by:silentreproach
2 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 1200 total points
ID: 19626901
....
open(LOG, ">>TrueGUI.log") or die "Could not open log: $!\n";
print LOG "Program running at " . localtime() . "\n";
while(1) {                                                
    $text=<STDIN>;
    chomp($text);
    print LOG "Text received='$text'\n";
    last if $text eq '3Click,MyForm.button1';
}
close(LOG);
                                                         
                                       
0
 
LVL 18

Assisted Solution

by:DropZone
DropZone earned 800 total points
ID: 19627037
Alternatively, instead of chomp(), you could use

     # remove all trailing whitespace
     # \x0a = LineFeed (ASCII 10)
     # \x0d = Carriage Return (ASCII 13)
     # \s = all whitespace (space, tab, newlines)
     $text =~ s/[\s\x0a\x0d]+$//;

If you only want the newlines trimmed, then remove the \s in the range.

    -dZ.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question