nakul has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I m i new monk and infact new to perl.

I am using Net::SSH:W32Perl module for running a command on a remote server. The command runs for a few minutes and i want to see the output on stdout as the command runs, not after the command has completed.

The code below helps me see the output only at the end of the command completion.

-------------------

my($stdout,$stderr,$exit) = $ssh->cmd($cmd); print "$stdout\n";

--------------------

Is there any way i could see the output on the fly as the command runs?

Thanks in advance.
- nakul

20071016 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Net::SSH:Perl output to STDOUT
by liverpole (Monsignor) on Oct 08, 2007 at 13:38 UTC
    Hi nakul,

    The documentation for Net::SSH::W32Perl references the documentation for Net::SSH::Perl, which has a debug method:

    $ssh->debug($msg) If debugging is turned on for this session (see the debug parameter to the new method, above), writes $msg to STDERR. Otherwise nothing is do +ne.

    I would recommend you try that first.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Net::SSH:Perl output to STDOUT
by perlofwisdom (Pilgrim) on Oct 08, 2007 at 13:32 UTC
    As a generic solution, the $| ($OUTPUT_AUTOFLUSH) variable is a toggle switch between 0 and 1. When set to 0, output is buffered then written. When set to 1, output is flushed immediately. I confess I don't know if there is anything internal to Net::SSH:W32Perl that would override this -- YMMV.