On 06/27/2013 06:07 PM, Rajeev Prasad wrote:
in the below code I am not able to print anything except whatever is in the
$pty. I want to print LINE_START: in the beginning of each line of the output,
but it does not print that, it only prints what the output of the exceuted
command produced. why is that so?
while(<$pty>) {
print "LINE_START: $. $_";
}
I am suspecting it has something to do with select STDOUT; $| = 1;, but i dont
know what.
complete code:
#!/usr/bin/perl
use strict;
use warnings;
use Net::OpenSSH;
use Expect;
select STDOUT; $| = 1;
select STDERR; $| = 1;
you left select on STDERR so print will print to that. you don't need
ever to set $| on stderr as it is not buffered like stdout is. and you
rarely need to set it on stdout as any print with a \n will flush stdout.
my ($pty, $pid) = $ssh->open2pty("$sudo_path -k; $sudo_path $su_path - $runas -c
\"$cmd\"")
or die "open2pty failed: " . $ssh->error . "\n";
use alternate delimiters on that string so you won't need the \ before
the " chars.
qq{$sudo_path -k; $sudo_path $su_path - $runas -c "$cmd"}
uri
--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/