Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Capture STDOUT and send to screen with open3

by karlgoethebier (Abbot)
on Mar 05, 2018 at 08:41 UTC ( [id://1210342]=note: print w/replies, xml ) Need Help??


in reply to Capture STDOUT and send to screen with open3

"...capture STDOUT and STDERR..."

Probably IPC::Run is what you want. See also Re: error variables after IPC::Run.

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Replies are listed 'Best First'.
Re^2: Capture STDOUT and send to screen with open3
by computergeek (Novice) on Mar 05, 2018 at 17:08 UTC

    I am currently trying to work out how to do it with IPC::Run and having trouble. Could you provide a code snipit of how to accomplish? The closest example I have right now is how to duplicate IPC::Open3

      Could you provide a code snipit of how to accomplish?

      Something like this maybe?

      Update: Now with STDERR support.

      use warnings; use strict; use IPC::Run qw/ run new_chunker /; my @cmd = ('yourcommand', 'arg1', 'arg2'); my (@out,@err); run \@cmd, '>', new_chunker("\n"), sub { my $line = shift; print $line; push @out, $line; }, '2>', new_chunker("\n"), sub { my $line = shift; print STDERR $line; push @err, $line; } or die $?;

        I am sorry, I am trying it and it hangs. Here is what I am executing: What am I doing wrong? Also, will this print a line real time from cat as if output were not being captured?

        my @cat = qw( cat ); run \@cat, '<pipe', \*PIPE, '>', new_chunker("\n"), sub { my $line = shift; print $line; push @out, $line; }, '2>', new_chunker("\n"), sub { my $line = shift; print STDERR $line; push @err, $line; } or die $?; print PIPE "some input\n"; close PIPE; print "out @out"; print "err @err";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found