in reply to assign open2 output to variable

G'day adrivez,

Welcome to the monastery.

"hi, i've been researching on this topic for quite some time"

Did your research include reading the IPC::Open2 documentation?

Based on that documentation, here's an example which I think emulates what you're trying to do:

#!/usr/bin/env perl use strict; use warnings; use autodie; use IPC::Open2; my $pid = open2(my $child_out, my $child_in, 'date'); my $from_child = <$child_out>; print 'From child: ', $from_child; waitpid $pid, 0; print 'Child exit status: ', $? >> 8, "\n";

Output:

From child: Sat 29 Mar 2014 03:49:33 EST Child exit status: 0

Note how my code reflects the documented example while yours bears little resemblance. As there's only a few lines of code, I suggest you compare the scripts: see where I've followed the documentation and ask yourself why you've done things differently — this may help you understand where you've gone wrong.

Also note that calling $child_out CIN and calling $child_in COUT will only serve to confuse you: it had me scratching my head when I first saw it!

[strict, warnings and autodie are all documented in Pragmas. You should use the first two of those in all your scripts!]

I'm not familiar with plink. What output do you get when you run the command you've posted from the command line? Does the output go to STDOUT or STDERR? If the latter, then you'll need IPC::Open3 to capture it.

There's further information in "perlipc: Bidirectional Communication with Another Process".

-- Ken

Replies are listed 'Best First'.
Re^2: assign open2 output to variable
by MidLifeXis (Monsignor) on Mar 28, 2014 at 17:55 UTC

    FYI: plink is PuTTY's command line version of ssh.

    --MidLifeXis