Perl interaction with Expect

E

Eric

Hello,

I'm not sure if this is a Perl question or an Expect question. But I
will start here.

I have written an Expect script that someone else is executing in
their Perl script. I would like my Expect script to return a string as
a value to this Perl script, not a boolean (i.e. integer).

For example, say my Expect script does something like this:

if (<this>) {
return "SUCCESS";
} else {
return "FAILURE";
}

The Perl script needs to have the value returned as either a "SUCCESS"
or "FAILURE".

I created a short Perl script that executes the Expect script by doing
the following:

my $rtnval = `rem.exp`;

Of course, that's not going to return the value I am looking for; it's
only going to print the output to stdout. And if I try:

my $rtnval = system("rem.exp");

that's only going to tell me if the system call passed or failed (i.e.
an integer), regardless of whether the Expect script deemed a success
or fail.

How can I call an Expect script from a Perl script and return a string
value? Is there some trick to getting an interaction between Perl and
Expect? I suppose I could do some kludge, like read the output into a
file and search the file for the response. But I'd rather avoid that
if possible.

Thanks in advance to all that respond.

Eric
 
E

Eric

Thanks for your response, David. Perhaps I should have clarified in my
posting that the Expect script is already written. So we'd prefer to
not have to rewrite it in Perl using the Expect module. What I am
looking for is a way to use my existing Expect script with minimal
modifications to the Perl script that is executing it.

Having said that, if I am missing something here - such as, the Expect
module can in fact be used for this purpose - please feel free to
point that out.

Thanks.

Eric
 
M

Mumia W.

Hello,

I'm not sure if this is a Perl question or an Expect question. But I
will start here.

I have written an Expect script that someone else is executing in
their Perl script. I would like my Expect script to return a string as
a value to this Perl script, not a boolean (i.e. integer).

For example, say my Expect script does something like this:

if (<this>) {
return "SUCCESS";
} else {
return "FAILURE";
}

The Perl script needs to have the value returned as either a "SUCCESS"
or "FAILURE".

I created a short Perl script that executes the Expect script by doing
the following:

my $rtnval = `rem.exp`;

Of course, that's not going to return the value I am looking for; it's
only going to print the output to stdout. And if I try:

my $rtnval = system("rem.exp");

that's only going to tell me if the system call passed or failed (i.e.
an integer), regardless of whether the Expect script deemed a success
or fail.

How can I call an Expect script from a Perl script and return a string
value? Is there some trick to getting an interaction between Perl and
Expect? I suppose I could do some kludge, like read the output into a
file and search the file for the response. But I'd rather avoid that
if possible.

Thanks in advance to all that respond.

Eric

AFAIK, you cannot get a string return value from a separate process. You
will either have to rewrite the Expect script to send the "SUCCESS" or
"FAILURE" to STDOUT, or you'll have to use the kludge you mentioned.
 
E

Eric

AFAIK, you cannot get a string return value from a separate process. You
will either have to rewrite the Expect script to send the "SUCCESS" or
"FAILURE" to STDOUT, or you'll have to use the kludge you mentioned.

Thanks for your response. If I do print the response to STDOUT (using
send_user or puts), the Perl script that's calling the Expect script
will have to be able read this output somehow (TBD). Is that correct?

Eric
 
E

Eric

Thanks for your response. If I do print the response to STDOUT (using
send_user or puts), the Perl script that's calling the Expect script
will have to be able read this output somehow (TBD). Is that correct?

Eric- Hide quoted text -

- Show quoted text -

Thanks to everyone that responded. I was able to get something to
work
by using bacticks to capture the response of the Expect program and
then parsing it using Perl.

This was a much easier problem than I was making it. I guess I got
caught up in the mindset of Perl-Expect interaction.


Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top