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.