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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |