Hi Monks,

Currently I am facing a problem in the below perl code snippet. The code below is not a original script rather i just simulated the problem using this

use IPC::Open2; use IPC::Open3; use strict; use IO::Select; my %ssh_handles; my @nodes = ('x','y','z'); my $val = "/test/*/26/*testingTESTING*"."\n"; my $command ='perl -e \"while(<>){chomp; \$val = \$_ ; \$res = \`ls -l + /mnt/\*/\$val \`;}\"'; foreach my $node ( @nodes ) { my ( $wtr , $rdr , $err ) = ""; #my $pid = open3 ( $wtr , $rdr , $err , "ssh $node \$command" ); #my $pid = open2 ( $wtr , $rdr , "ssh $node \"$command\"" ); my $pid = open2 ( $wtr , $rdr , "ssh $node 'perl -e \"while(<>){cho +mp;\$val=\$_;\$res=\`ls -l /mnt/\*/\$val\`;}\"'" ); $ssh_handles{$node}{in} = $wtr if ( $wtr ); $ssh_handles{$node}{out} = $rdr if ( $rdr ); $ssh_handles{$node}{err} = $err if ( $err ); } foreach my $node ( sort keys ( %ssh_handles ) ) { print {$ssh_handles{$node}{in}} $val; close $ssh_handles{$node}{in}; my @ready; my $data = ""; my $select = IO::Select->new($ssh_handles{$node}{out}); if(@ready = $select->can_read(4.0)) { foreach my $rh (@ready) { my ($len,$buffer); if($len = sysread($rh, $buffer, 4000)) { if(!defined $len) { return undef; } $data .= $buffer; } } } print "[",$data,"]\n"; }
1) In the above code i would like to get the STDOUT messages but am not getting it.
I spent the whole day in this issue (tried by using open2 , simple open with | etc.), but i could not able to solve. So can you people please help me to resolve this issue.

Thanks & Regards,
R.Sivakumar


In reply to How and When to read STDOUT after using open3() funciton? by siva_kumar25

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.