Try

system 'echo "rYr" | phylip sub_program_1';

or

system 'echo -e "r\nY\nr" | phylip sub_program_1';

The latter would be appropriate in case you have to press Enter after typing the respective letter when you do it interactively.

The way this works is essentially as follows (somehwat simplified): each program has three standard handles for I/O: stdin, stdout, stderr (we can forget about stderr for the moment).

When you run a program from the command line "normally" (i.e. without a pipe or redirection) those standard handles are connected to the terminal where your command shell runs in.  What you type on the keyboard is forwarded to the program as input, and what the program outputs is displayed in the terminal.  When you connect two programs via a pipe

program_A | program_B

stdout of A is being sent to stdin of program B. The respective handles are also disconnected from the terminal, which means that B no longer gets its input from the keyboard, but from program A (and the output of A is no longer displayed in the terminal).

In your particular case, program A is the command "echo", which simply sends to stdout whatever you pass it as arguments, which then ends up as input for program B (phylib) as if you had typed it on the keyboard.  In other words, the idea is simply to make echo send to stdout exactly the same characters that you would have typed interactively otherwise.

Also, program B only reads as many characters as it wants at a time, even if program A has output everything at once. The associated buffering (and blocking of I/O, if needed) is handled behind the scenes by the OS.


In reply to Re^3: How to execute external programs from perl script by Anonyrnous Monk
in thread How to execute external programs from perl script by chak9988

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.