Ok this question came to me after reading
Interprocess Communication.
That question covered something I have been trying to do for a long time, namely the ability to feed information to a process that won't accept standard shell input redirection. i.e. telnet ( when it asks for the password )
So I attempted to implement the Open2 code given in response
here, and ran into this problem:
The first time I attemt to read from the read filehandle, the program blocks until broken. I tried this with other programs as well, and the same thing occurs on any program that requires user input. It works fine on programs like hostname that do not require user input. Here is the code that I am using:
#!/usr/local/bin/perl
use IPC::Open2;
$SIG{CHLD} = sub { $i = 1 };
local ( *RD, *WR );
print "Opening $ARGV[0]\n";
my $child = open2(\*RD, \*WR, "$ARGV[0]") || die "couldn't open $ARGV[
+0]";
print "Finished opening $ARGV[0]\n";
$i = 0;
while (1) {
$prompt = <RD>;
print $prompt;
last if ( $i = 1 );
$cmd = <STDIN>;
$cmd1 = "'".$cmd."'";
print WR "$cmd";
}
NOTE: The code is not complete, but I wasn't going to bother adding things like alrm handlers and whatnot until I knew that this would at least work in a normal situation.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.