Here is the Output with Data::Dumper

I have also given the script below

nandi@nandi-laptop:~/begperl$ perl try_expect.pl Selecting sproc1 CPU sproc1> sproc1>loadprg a.out Endianness of the ELF file:0 .text matched [text segment] flag = 0x3 .ctors matched [data segment] flag = 0x3 .dtors matched [data segment] flag = 0x3 .data matched [data segment] sproc1>run Run mode selected Buffer Empty = 32 Buffer Empty = 32 Buffer Empty = 32 Buffer Empty = 32 Buffer Empty = 28 SWBKPT hit for SLOT 1..!! PC-Value : 0x124 Blk Count = 1 Cycles +: 332 $VAR1 = [ 1, undef, 'SWBKPT hit for SLOT 1..!! PC-Value : 0x124 Blk Count = + 1 Cycles : 332', 'loadprg a.out Endianness of the ELF file:0 .text matched [text segment] flag = 0x3 .ctors matched [data segment] flag = 0x3 .dtors matched [data segment] flag = 0x3 .data matched [data segment] sproc1>run Run mode selected Buffer Empty = 32 Buffer Empty = 32 Buffer Empty = 32 Buffer Empty = 32 Buffer Empty = 28 ', ' ', bless( \*Symbol::GEN0, 'Expect' ) ];

$VAR1 shows that the pattern has matched in 1 poition ie 0 postion of my @match array

undef indicating no error

then comes the successfully_matching_string

then comes the before_match

finally after_match... But here the after match is empty.. So i gussed it must be "\n"

To verify that i did a print with Match_after in between "Hello World"

As it comes out my guess was right

So expect is sending "\n\n" before simulator finishes execution. So I put a sleep as advised.. :( Didnt work either

Here is the script..

#!/usr/bin/perl use warnings; use strict; use Expect; use Data::Dumper; chdir '/home/nandi/simulator/' or die "Can't change directory : $!"; my $expect = Expect->new; my $command = './simulator/pruthvi.out'; my @parameters = qw(-m 4); my $timeout = 2; my @pattern_list; my @match = "SWBKPT hit for SLOT 1..!! PC-Value : 0x124 Blk C +ount = 1 Cycles : 332"; $expect->spawn($command,@parameters ) or die "Cannot spawn : $!\n"; $expect->expect($timeout,"Selecting sproc1 CPU"); $expect->send("\n\n"); $expect->expect($timeout,"sproc1>"); $expect->send("loadprg a.out\n"); $expect->expect($timeout,'sproc1>'); $expect->send("run\n"); @pattern_list = $expect->expect($timeout,@match); print Dumper(\@pattern_list); #$expect->expect($timeout,"SWBKPT hit for SLOT"); #my $match_after = $expect->after(); #print "Hello $match_after World"; sleep 3; $expect->send("\n\n"); #$expect->expect("sproc1>"); #$expect->send("dump mem 74010 4 \n"); #$expect->expect("sproc1>"); #$expect->send("quit\n");

Now what I am supposed to do.. I entered "\n" at the end of string in @match but that too didnt work out.

I think CPAN Expect is not that friendly with Perl compared to Shell. I have no problem running expect in SHELL script.


In reply to Re^4: Need Help in running Expect script in Perl by subhasishn@yahoo.com
in thread Solved: Need Help in running Expect script in Perl by subhasishn@yahoo.com

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.