NET:TELNET data output

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Is there a way I can get NET::TELNET to print out the data realtime
instead of after the command is finished?
My command:
@lines = $conn->cmd("./");
print @lines;

Where contains:
for i in 1 2 3 4 5 6 7
ls /dev
sleep 5

Nothing gets outputed until the script finishes


Re: NET:TELNET data output (bigdogdan2) wrote:

Quoted text here. Click to load it

You can do something like the following (untested, and possibly
incorrect, but I've done similar before):

while (1) {
    my $line = $conn->getline;
    ## check to see if you've got the shell prompt back yet
    ## and exit if you have
    ## do something with $line
Bright eyes/burning like fire,           | Kevin Michael Vail
Bright eyes/how can you close and fail?  |
How can the light that shone so brightly | . . . . . . . . . .
Suddenly shine so pale?/Bright eyes      |  . . . . . . . . .

Re: NET:TELNET data output

I couldn't get your suggestion to work.  

while (1) {
        my $line = $conn->getline;
        print $line;
        if ($line == "[root@(none) root]") {

actually, I couldn't even get
$conn->cmd('ls /dev');
my $line = $conn->getline;
print $line;

Do you see any problem with this?


Quoted text here. Click to load it

Re: NET:TELNET data output (bigdogdan2) writes:
Quoted text here. Click to load it

You can send the command and read its response a block at a

    use Net::Telnet;
    $t = new Net::Telnet(-prompt => "/\Q$prompt\E$/");
    $t->login($user, $passwd);
    while ($blk = $t->get) {
        print $blk;
        $buf .= $blk;
       last if $buf =~ /\Q$prompt\E$/;

or you can just make input_log() (i.e. the bytes read from
the remote host) go to stdout:

    $t->cmd(-string => "",
            -timeout => 60);

Site Timeline