Hi Monks,

I am new to perl and still in learning phase.

I was trying to write an expect script which invokes an simulator and with few inputs gives me an output.

Here is the prob.. I am able to invoke the simulator, first few expect and send request also work fine. Then simulator throws an output, which is a line with few words and ending with newline. Here I need to send an Enter("\n") to the simulator so that I get the prompt back. Which I am unable to do.

Please find the output of the simulator without script and with script below. Also the script that i wrote.

Without Script

Selecting sproc1 CPU (Press Enter Here) sproc1>loadprg a.out (On prompt gave loadprg command) 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(on prompt gave run command) 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(Here is the problem.. Unable to give Enter input to get back th +e prompt) sproc1>dump mem 74010 4(On prompt gave dump command) 0x74010:: 0x00000000 sproc1>quit

Output of Simulator with Script

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

Here is the script

use Expect; chdir '/home/...some place.....' or die "Can't change directory : $!"; my $expect = Expect->new; my $command = './simulator/pruthvi.out'; my @parameters = qw(-m 4); my $timeout = 2; #$expect->raw_pty(0); $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("sproc1>"); $expect->send("run\n"); $expect->expect($timeout,"SWBKPT hit for SLOT"); $expect->send("\n\n"); $expect->expect("sproc1>"); $expect->send("dump mem 74010 4 \n"); $expect->expect("sproc1>"); $expect->send("\n");

I tried the same thing in shell script, thats working fine

Here's the shell script

#!/bin/sh #!/usr/bin/expect cd /home/...some place../ expect -c ' set timeout 2 set file [open /home/aaa w] # log_user 1 spawn ./simulator/pruthvi.out -m 4 expect "Selecting sproc1 CPU" send "\n\n" expect "sproc1>" send "loadprg a.out\n" expect "sproc1>" send "run\n" expect "SWBKPT hit for SLOT" send "\n" expect "sproc1>" send "dump mem 74010 4 \r" expect "sproc1>" puts $file "$expect_out(buffer)" send "quit\n" #puts $file "$expect_out(buffer)" expect eof '

I would appreciate if someone could help me out.


In reply to 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.