Good luck with that. :)
In the general case, you risk deadlock. To avoid deadlock, you run into the areas where Perl 5 tends to disappoint: threads or async I/O.
Even if you do something either problematically complicated or "less elegant" (writing either the input or the output to a temporary file) in order to avoid deadlock, then you run into the decades-old problem of libc not flushing output the same. (It is a shame that in those decades, libc has still not been taught to flush "like to a TTY" if some environment variable is set.)
To solve that problem, you either have to have the ability to modify the code being run in the subprocess or you have to deal with pseudo ttys.
I usually find that the easiest way to deal with pseudo ttys is to ssh to localhost.
Of course, this is why "expect" was built. But getting a working Perl version of "expect" can be a bit of a challenge (at least the last time I saw somebody try).
|