Thanks ikegami.
You are right. Hmm, so my basic mistake was not to put the second pump (for reading back to $TOK_OUT). During my Internet browsing I didn't find any example with 2 pumps.
Just for the sake of curiosity. $TOK_OUT doesn't seem to be an ordinary variable. If you run the following program:
#!/usr/bin/perl -w
use IPC::Run qw(start pump finish timeout);
my $tok_program = "/bin/./cat";
my ($TOK_IN, $TOK_OUT, $TOK_ERR);
my $TOK = start [$tok_program],
'<', \$TOK_IN,
'1>pty>',\$TOK_OUT,
'2>', \$TOK_ERR ,
debug => 0 or die "Error: $?;\n";
while (my $line = <STDIN> ) {
# Send input.
$TOK_IN = $line;
pump $TOK while length $TOK_IN;
# Wait for output.
pump $TOK while $TOK_OUT !~ /\n\z/;
my $msg = $TOK_OUT;
chomp($msg);
print "out:$TOK_OUT;;MESSAGE=$msg;;END\n";
$TOK_OUT = '';
}
finish($TOK) or die "returned: $?";
You will get:
out:1. line
;;ENDSAGE=1. line
out:2. line
;;ENDSAGE=2. line
Instead of:
out:1. line
;;MESSAGE=1. line;;END
out:2. line
;;MESAGE=2. line;;END
Do you know why?
Once more - thank you!
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.