Tom Moertel wrote:

If you are on a Unix system, you can redirect STDIN to pull input from a file. You can also open the file a second time for appending to obtain an independent file descriptor. You can write into this descriptor to inject input into STDIN. ... Using this approach, you can inject on the fly, interleave injections and reads, and also simulate EOF input conditions.

Yesterday I was frustrated by the fact that, while there are several ways to redirect where STDIN is going to (by the command-line; by IO::Handle; etc.), there didn't seem to be a robust way of changing where it is coming from. After I logged off, I got to thinking about File::Temp (a module I've been using a lot lately as part of test building in the Phalanx project). I realized that there probably would be a way to use File::Temp to, in effect, fake out STDIN. But I then thought, "That's a lot of work for a simple problem."

Well, your subroutine does do a lot of work, but it has the virtue of hiding the work in a subroutine. I'll try to check it out today. Thanks for taking the time to present your approach.

Jim Keenan


In reply to Re^2: Pre-empting STDIN during Testing by jkeenan1
in thread Pre-empting STDIN during Testing by jkeenan1

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.