How do I implement the following, including catching stdout and stderr with run3?
the docs claim
compared to system(), qx'', open "...|", open "|..."
... BUT ...
Note that this form of redirecting the child's I/O doesn't imply any form of concurrency between parent and child - run3()'s method of operation is the same no matter which form of redirection you specify.
I'm confused, is it even possible to have a bidirectional communication between two simultaneously running processes with run3?
If not what's the appropriate solution?
use v5.12; use warnings; use IPC::Run3; my ($cmd, $in, $out, $err); $cmd = 'perl ./server.pl'; open my $fh_in,"|-", $cmd; #my @in; #run3($cmd, \@in); sub out { $fh_in->say(@_); } my $doit; for my $try (2,3,2) { $doit = "$;" x $try; out($doit); out($_) for 1..$try; out($doit); } out("EOF");
use v5.12; use warnings; STDOUT->autoflush; my $doit; my $input; while ( my $line = <STDIN> ) { unless ( defined $doit ){ $doit = $line; last if $doit eq "EOF"; next; } if ($line eq "$doit") { doit(); undef $doit; } else { $input .= $line; } } say "exit by $doit"; exit; sub doit { print "((( STDOUT ::: $doit"; print $input; print "))) STDOUT ::: $doit"; #warn "STDERR:",$input," "; $input =""; }
((( STDOUT ::: 1 2 ))) STDOUT ::: ((( STDOUT ::: 1 2 3 ))) STDOUT ::: ((( STDOUT ::: 1 2 ))) STDOUT ::: exit by EOF
found this
Bidirectional Communication with Another Process
doesn't seem to be overly portable and I doubt run3 is the solution...
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Concurrency with IPC::Run3 ? by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |