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

Can't locate object method "autoflush" via package "FileHandle" at /usr/share/perl5/Expect.pm line 107. Hi All, I'm new to perl and facing a problem........ I'm using a perl expect script to login to a server. But getting the below error. pls help
#! / Usr / bin / perl use strict; use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "xx.xx.xx", password=> 'passwd', user => 'usr', raw_pty => 1, timeout => 10 ); my $login_output = $ssh->login(); if ($login_output !~ /#/) { die "Login has failed. Login output was $login_output"; } print $login_output; my $who = $ssh->exec("show version"); print ($who); $ssh->close();

Replies are listed 'Best First'.
Re: Can't locate object method "autoflush"
by wazat (Monk) on Dec 09, 2013 at 18:48 UTC

    This may be an obvious question, but is your perl complete? The error is complaining about FileHandle::autoflush, which should be there via inheritance from IO:Handle. Does the following work, or does it give you the same error?

    #!/bin/perl -w use strict; use FileHandle; FileHandle::autoflush STDOUT 1;
Re: Can't locate object method "autoflush"
by ikegami (Patriarch) on Dec 09, 2013 at 19:04 UTC
    Does adding use FileHandle qw( ); help?
Re: Can't locate object method "autoflush"
by taint (Chaplain) on Dec 09, 2013 at 16:30 UTC

    I'm not sure if what you've provided here, is your entire script. But I think you're going to need to somehow manage the input stream. Which I believe is why you're seeing the error you are. I don't have an example. But I see the pod for Net::SSH::Expect provides quite a few of them. Maybe one of them will get you where you want to be. :)

    --Chris

    EDIT Updated external link to be more specific.
    Yes. What say about me, is true.
    
Re: Can't locate object method "autoflush"
by james_culling (Novice) on Dec 10, 2013 at 06:23 UTC
    Thanks.. It started working after adding use FileHandle.