Perl interaction with Expect

Discussion in 'Perl Misc' started by Eric, Feb 14, 2007.

  1. Eric

    Eric Guest

    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
     
    Eric, Feb 14, 2007
    #1
    1. Advertising

  2. Eric

    Guest

    , Feb 14, 2007
    #2
    1. Advertising

  3. Eric

    Eric Guest

    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
     
    Eric, Feb 15, 2007
    #3
  4. Eric

    Mumia W. Guest

    On 02/14/2007 02:54 PM, Eric wrote:
    > 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.


    --
    Windows Vista and your freedom in conflict:
    http://techdirt.com/articles/20061019/102225.shtml
     
    Mumia W., Feb 15, 2007
    #4
  5. Eric

    Eric Guest

    On Feb 14, 11:56 pm, "Mumia W." <paduille.4060.mumia.w
    > wrote:
    > On 02/14/2007 02:54 PM, Eric wrote:
    >
    >
    >
    >
    >
    > > 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.
    >
    > --
    > Windows Vista and your freedom in conflict:http://techdirt.com/articles/20061019/102225.shtml- Hide quoted text -
    >
    > - Show quoted text -


    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
     
    Eric, Feb 15, 2007
    #5
  6. Eric

    Eric Guest

    On Feb 15, 9:00 am, "Eric" <> wrote:
    > On Feb 14, 11:56 pm, "Mumia W." <paduille.4060.mumia.w
    >
    >
    >
    >
    >
    > > wrote:
    > > On 02/14/2007 02:54 PM, Eric wrote:

    >
    > > > 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.

    >
    > > --
    > > Windows Vista and your freedom in conflict:http://techdirt.com/articles/20061019/102225.shtml-Hide quoted text -

    >
    > > - Show quoted text -

    >
    > 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
     
    Eric, Feb 15, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MarkD
    Replies:
    0
    Views:
    746
    MarkD
    Dec 4, 2003
  2. Simon Strandgaard

    how to expect eof with expect+pty

    Simon Strandgaard, Dec 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    358
    Simon Strandgaard
    Dec 20, 2006
  3. Graham Wood
    Replies:
    4
    Views:
    109
    Alan J. Flavell
    Sep 5, 2003
  4. Franklin Lee

    Help with Perl Expect.

    Franklin Lee, Feb 26, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    179
    Charles DeRykus
    Mar 1, 2004
  5. Phil
    Replies:
    0
    Views:
    169
Loading...

Share This Page