siva_kumar25 has asked for the wisdom of the Perl Monks concerning the following question:
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
1) In the above code i would like to get the STDOUT messages but am not getting it.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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How and When to read STDOUT after using open3() funciton?
by quester (Vicar) on Feb 02, 2007 at 10:56 UTC |