Interacting With A Terminal App

Discussion in 'Perl Misc' started by tpurl, Mar 6, 2006.

  1. tpurl

    tpurl Guest

    Hi, I've searched for hours on how to do this to no avail. Any help I
    can get would be greatly appreciated!

    I would like to interact with a console app that expects you to log in,
    send it commands, and then log out. A typical session might look like
    this:

    $ ./myapp -u user -p pass
    myapp> setval 10
    myapp> getval
    (prints 10)
    myapp> exit
    $

    I've heard that you can do something like this with the expect module,
    but I would rather not have to install it on the machine with which I'm
    working. I tried something like this:

    my $myapp = "/usr/bin/myapp -u user -p pass";
    open(MYAPP, "|$myapp") or die "Cannot execute $myapp: $!";
    print MYAPP "setval 10";
    print MYAPP "getval";
    print MYAPP "exit";
    my @lines = <MYAPP>; # read the value returned from the getval command
    close(MYAPP);

    However, this just blows up in my face. Does anyone point me in the
    right direction on this one?

    Thanks again!

    Tom Purl
     
    tpurl, Mar 6, 2006
    #1
    1. Advertising

  2. tpurl

    J. Gleixner Guest

    tpurl wrote:
    > Hi, I've searched for hours on how to do this to no avail. Any help I
    > can get would be greatly appreciated!
    >
    > I would like to interact with a console app that expects you to log in,
    > send it commands, and then log out. A typical session might look like


    > I've heard that you can do something like this with the expect module,
    > but I would rather not have to install it on the machine with which I'm
    > working.


    Why not? You'd be finished by now. You can simply install it in your
    directory:

    perldoc -q "How do I keep my own module/library directory"

    >
    > my $myapp = "/usr/bin/myapp -u user -p pass";
    > open(MYAPP, "|$myapp") or die "Cannot execute $myapp: $!";
    > print MYAPP "setval 10";
    > print MYAPP "getval";
    > print MYAPP "exit";
    > my @lines = <MYAPP>; # read the value returned from the getval command
    > close(MYAPP);
    >
    > However, this just blows up in my face. Does anyone point me in the
    > right direction on this one?


    Expect is the best option. If you want to get your hands dirty,
    perldoc IPC::Open2.
     
    J. Gleixner, Mar 6, 2006
    #2
    1. Advertising

  3. tpurl <> wrote:

    > I've searched for hours on how to do this to no avail.



    Did you search the Perl Frequently Asked Questions?


    > I would like to interact with a console app that expects you to log in,
    > send it commands, and then log out.



    perldoc -q expect

    How can I write expect in Perl?


    > I've heard that you can do something like this with the expect module,



    Oh.


    > but I would rather not have to install it on the machine with which I'm
    > working.



    Why would you rather not have to install it on the machine with which
    you're working?


    > open(MYAPP, "|$myapp") or die "Cannot execute $myapp: $!";


    > my @lines = <MYAPP>; # read the value returned from the getval command


    > However, this just blows up in my face. Does anyone point me in the
    > right direction on this one?



    perldoc -q pipe

    How can I open a pipe both to and from a command?


    But that requires another module that you would probably
    rather not install...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 7, 2006
    #3
  4. tpurl

    tpurl Guest

    Thanks a lot for the help guys! "Administrative constraints" are
    keeping me from installing the Expect module on the servers with which
    I'm working. Thanks for pointing me in the direction of the pipe
    module.
     
    tpurl, Mar 7, 2006
    #4
  5. "tpurl" <> wrote in news:1141751530.757948.183100
    @v46g2000cwv.googlegroups.com:

    > Thanks a lot for the help guys! "Administrative constraints" are
    > keeping me from installing the Expect module on the servers with which
    > I'm working. Thanks for pointing me in the direction of the pipe
    > module.
    >


    You should quote some context when you reply.

    Have you read:

    "J. Gleixner" <> wrote in news:Lf3Pf.29
    $:

    > Why not? You'd be finished by now. You can simply install it in your
    > directory:
    >
    > perldoc -q "How do I keep my own module/library directory"
    >


    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 7, 2006
    #5
    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. John
    Replies:
    2
    Views:
    752
    Thomas Weidenfeller
    May 19, 2005
  2. Sells, Fred
    Replies:
    0
    Views:
    275
    Sells, Fred
    Jul 3, 2007
  3. gaurav kashyap
    Replies:
    3
    Views:
    6,735
    Paul Boddie
    Oct 31, 2008
  4. Steve
    Replies:
    2
    Views:
    980
    edicionsdigitals.com edicions digitals xarxa socia
    Dec 7, 2010
  5. Anthony M. Saffer

    Interacting w/another App on Win32

    Anthony M. Saffer, Apr 11, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    103
    Anthony M. Saffer
    Apr 12, 2004
Loading...

Share This Page