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


In reply to Re: assign open2 output to variable by kcott
in thread assign open2 output to variable by adrivez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.