Expext-1.12_ref_003 
Author Message
 Expext-1.12_ref_003

Hello all,

Now we will play with 2 process.
  first process "cat data"
  snd process "grep DATA"
When you start the script below, you will probably see that you get
on your screen
  1) every line of the file "data"
  2) the result of the grep
We should only get the line with DATA in it. Why this echo ??
The answer is in the man.

Run the script again but uncomment the line:   #$pod->exp_stty('-echo');
Now you shoul only get the lines with DATA colored in blue.
That also is mentionned in the man but it took me 2 days before I got
it.

A bientot in my next mail  (...ref_004)

Pierre.

PS: I hope I'am not a "pain in the neck"  (Is that expression correct
??)

#!/usr/bin/perl -w
use strict;
use Expect;
use Term::ANSIColor qw(:constants);   # just for the fun
 $Term::ANSIColor::AUTORESET = 1;

#################
# linux (Debian) + Expect-1.12
#################

my ($match_num,$error,$match,$before,$after);
my ($pid,$pod,$string1,$string2);
my ($start);

print "Expect_version: ",Expect::version(undef),"\n";
print "Perl_version  : $]\n";

#  now I would like to play with this stuff !!
$pid=Expect->spawn("/bin/cat","data") or die "can't spawn\n";
$pod=Expect->spawn("/bin/grep","DATA") or die "can't spawn\n";
$pid->log_stdout(0); # i want no output from my spawned process to
STDOUT
$pid->exp_internal(0);  # turn DEBUG on
# this will suppress the echoing from $pod (/bin/grep DATA)
#$pod->exp_stty('-echo');
$pod->log_stdout(0); # i want no output from my spawned process to
STDOUT
$pod->exp_internal(0);  # turn DEBUG on
$Expect::Multiline_Matching = 1;

$start=time;
expect("10",
       '-i',$pid,[
                   # regexp get every incoming lines
                     '-re','^.*\r\n',sub {my $exp=shift;
                                         $string2=$exp->exp_match();  
                                         print BOLD RED $string2;
                                         print $pod $string2;
                                         exp_continue_timeout;
                                         }
                 ],
       '-i',$pod,[
                     '-re','^.*\r\n',sub {my $exp=shift;
                                         $string1=$exp->exp_match();  
                                         $string1=~s/\s+//;
                                         $string1=~s/\r\n//;
                                         print BOLD BLUE
"<",$string1,">\n";
                                         exp_continue_timeout;
                                         }
                 ],
);
print "\nstart_time: $start\n";
print "end_time: ",time,"\n";
print "elapsed_time: ",time - $start,"\n";
print BOLD RED "Out_of_expect\n";

##   input file needed for the exercice  :-)  Have fun
#10316 B    1713 FFFF_0003 FFFF_9D04 0C00 4820 .... 0080:0001 002A DUP
20:56:56.2
#           DATA 0300 5C7F
#           UBUF 0108 0549 04A1 9003 A390 0118 1E89 8202
#UBUF 6C83 010C 3083 3230 3234 3636 3731 7038
#           UBUF A109 3232 3230 3332 3132
##  this only noise
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:0002 0007 DUP
20:56:56.5
#           DATA 0300 FF50
#           UBUF 0108 01C9
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:0003 0007 DUP
20:56:56.5
#           DATA 0300 0060
#           UBUF 0108 01C9 0118 XX89
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:0004 0007 DUP
20:56:56.6
#           DATA 0300 FF61
#           UBUF 0108 01C9 0118 XX89
#
#10315 B    1713 FFFF_0003 FFFF_9D04 0C00 4820 .... 0080:0005 0008 DUP
20:57:00.4
#           DATA 0300 5C50
#           UBUF 0108 4D49 0208 9F84
##  this only noise
#
#10315 B    1713 FFFF_0003 FFFF_9D04 0C00 4820 .... 0080:0006 0008 DUP
20:57:00.4
#           DATA 0300 5C60
#           UBUF 0108 4D49 0208 9F84
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:0007 0004 DUP
20:57:00.4
#           DATA 0300 0050
#           UBUF 0108 5AC9
#10315 B    1713 FFFF_0003 FFFF_9D04 0C00 4820 .... 0080:0008 0008 DUP
20:57:00.4
#           DATA 0300 2461
#           UBUF 0108 4D49 0208 9F84
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:0009 0004 DUP
20:57:00.4
#           DATA 0300 FF60
#           UBUF 0108 5AC9
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:000A 0004 DUP
20:57:00.5
#           DATA 0300 FF61
#           UBUF 0108 5AC9
#
#10316 B    1713 FFFF_0003 FFFF_9D04 0C00 4820 .... 0080:000B 002A DUP
20:57:08.8
#           DATA 0300 FF7F
#           UBUF 0108 054F 04A1 9003 A390 0118 1E89 8202
#           UBUF 6C83 010C 3083 3230 3234 3636 3731 7038
#           UBUF A109 3232 3230 3332 3132
##  this only noise
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:000C 0007 DUP
20:57:08.9
#           DATA 0300 FF60
#           UBUF 0108 01CF 0118 XX89
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:000D 0007 DUP
20:57:08.9
#           DATA 0300 FF61
#           UBUF 0108 01CF 0118 XX89
#10321 B    1713 FFFF_9D04 FFFF_9D05 0C00 4820 .... 0080:000E 0004 DUP
20:57:08.9
#           DATA 0300 FF50
#           UBUF 0108 01CF
#
#10315 B    1713 FFFF_0003 FFFF_9D04 0C00 4820 .... 0080:000F 0008 DUP
20:57:13.9
#           DATA 0300 5C60
#           UBUF 0108 4D4F 0208 9F84
##  this only noise
##  this only noise



Sun, 18 Apr 2004 04:12:49 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Expect-1.12_ref_003

 

 
Powered by phpBB® Forum Software