That was what I thought, but interestingly, I didn't get the prompt back through $reader, Hm.. where did it go?

If I can get it, the whole thing is resolved.

Update:

  1. tye's suggestion definitely makes sense, as it might be just the prompt is not flushed yet. But I tried this:
    #!/usr/bin/perl use IPC::Open2; use strict; my ($reader, $writer); my $pid = open2($reader, $writer, "sh") || die "failed"; print $writer "history\n"; my $buffer; sysread($reader, $buffer, 4000); print "[", $buffer, "]\n"; print $writer "ls\n"; sysread($reader, $buffer, 4000); print "[", $buffer, "]\n";
    There is no prompt being printed between two prints. So it means/proves that the prompt is NOT THERE, doesn't matter what it is, but I do like tye's suggestion, it is 100% logical.

  2. I did a research, and someone said on internet that sh does not output prompt if it is not used interactively. This matches my result.

    But is there a switch to toggle this feature?

In reply to Re: (Expect) Re: question for open2, and by the way, resolves an old thread by pg
in thread question for open2, and by the way, resolves an old thread by pg

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.