external program

Discussion in 'Perl Misc' started by Alex Lee, Sep 15, 2004.

  1. Alex  Lee

    Alex Lee Guest

    Dear all: I am having a problem that is driving me nuts and I hope some
    one can help me.

    Basically I need to access another program/script from my perl script.
    This is easy. It is not when the program ask for an input (ie yes or
    no).

    here is an example:
    ------------------------------------
    -- external script
    $|=1;
    print "enter something \n";
    my $i = <>;
    print "your input: $i";
    -------------------------------------

    -- my script:
    open(TE, "perl externalScript.pl|") or die "no";
    while(<TE>){
    print "$_";
    ### need to print "hello world \n\r" when $_ =~ /enter/;
    }

    ---------------------------------------
    basically I need the external program to accept my input:
    example: print "hello world \n\r" when $_ =~ /enter/;

    I tried many different ways, but none works so far. I figure that is
    probablt has something to do with redirecting my STDOUT from my script
    to the external program. How I do not know. If anyone can help, it
    would be greatly apprecaited.

    thanks.
    Alex Lee, Sep 15, 2004
    #1
    1. Advertising

  2. Alex  Lee

    Paul Lalli Guest

    "Alex Lee" <> wrote in message
    news:ci9pt8$...
    > Basically I need to access another program/script from my perl script.
    > This is easy. It is not when the program ask for an input (ie yes or
    > no).
    >
    > here is an example:
    > ------------------------------------
    > -- external script
    > $|=1;
    > print "enter something \n";
    > my $i = <>;
    > print "your input: $i";
    > -------------------------------------
    >
    > -- my script:
    > open(TE, "perl externalScript.pl|") or die "no";
    > while(<TE>){
    > print "$_";
    > ### need to print "hello world \n\r" when $_ =~ /enter/;
    > }
    >
    > ---------------------------------------
    > basically I need the external program to accept my input:
    > example: print "hello world \n\r" when $_ =~ /enter/;


    Have a look at the Perl FAQ on this topic:

    perldoc -q pipe
    "How can I open a pipe both to and from a command?"

    Paul Lalli
    Paul Lalli, Sep 15, 2004
    #2
    1. Advertising

  3. Alex Lee wrote:
    > Dear all: I am having a problem that is driving me nuts and I hope
    > some one can help me.
    >
    > Basically I need to access another program/script from my perl script.
    > This is easy. It is not when the program ask for an input (ie yes or
    > no).


    You may want to check the Expect module

    jue
    Jürgen Exner, Sep 16, 2004
    #3
    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. Nibha Kothari

    Invoking an external program in ASP.NET

    Nibha Kothari, Jul 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    438
    Nibha Kothari
    Jul 22, 2003
  2. Cédric Rossé
    Replies:
    2
    Views:
    1,032
    Cédric Rossé
    Sep 29, 2004
  3. Dmitry Duginov

    Run external program during BUILD?

    Dmitry Duginov, May 2, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    709
    Chris R. Timmons
    May 2, 2005
  4. Scott Allen
    Replies:
    8
    Views:
    10,936
    Scott Allen
    May 2, 2004
  5. Mellow Crow
    Replies:
    6
    Views:
    418
    Richard Cornford
    Nov 4, 2005
Loading...

Share This Page