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

Hi,

I am trying to bring together Net::SSH::Perl and Net::Telnet::Cisco so that I can utilize the ease of use of the latter with the SSH capability of the former. Net::SSH::Perl only allows me an interactive shell on the device tied to STDIN and STDOUT, but Net::Telnet::Cisco will allow me to open an existing file handle with fhopen($fh).

So I want N::T::C to use STDIN and STDOUT... but how do I represent those as a single file handle so that I can pass that file handle as the argument in fhopen($fh)?

Thanks in advance,
Scott

  • Comment on STDIN and STDOUT as a single filehandle?

Replies are listed 'Best First'.
Re: STDIN and STDOUT as a single filehandle?
by PodMaster (Abbot) on May 31, 2004 at 16:59 UTC
    perltie

    update: Here is a start

    package ReadOneWriteOtherone; use strict; use warnings; sub TIEHANDLE { my( $self, $in, $out ) = @_; $self = bless { in => $in, out => $out}, $self; return $self; } sub PRINT { my $self = shift; $self = $self->{out}; print $self @_; } sub READLINE { my $self = shift; $self = $self->{in}; readline $self; } sub CLOSE { my $self = shift; close $self->{in}; close $self->{out}; } 1; package main; unless( caller ){ tie *BLOG => ReadOneWriteOtherone => \*STDIN, \*STDOUT or die "Cou +ldn't tie BLOG : $!"; print tied(*BLOG),$/; print tied(*BLOG)->{in},$/; print tied(*BLOG)->{out},$/; print "Enter some input buddy and hit enter : $/"; print BLOG "You entered: ", scalar <BLOG>; } __END__ $$ perl ReadOneWriteOtherone.pm ReadOneWriteOtherone=HASH(0x1abf1a4) GLOB(0x1ab7f34) GLOB(0x1ab5054) Enter some input buddy and hit enter : Hi there You entered: Hi there

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Okay I get the gist of that, but as it was with the 'ReadOneWriteOther.pm' I was getting an error:
      Can't locate object method "FILENO" via package "ReadOneWriteOther" at /usr/lib/perl5/site_perl/5.8.0/Net/Telnet.pm line 560.
      So I figured I had to just add a 'sub FILENO' in and choose to return either 'fileno $self->{in}' or out, but neither worked. Both get the error:
      stat() on unopened filehandle TERM at /usr/lib/perl5/site_perl/5.8.0/Net/Telnet.pm line 578.
      ... and then when I open the shell with Net::SSH::Perl, it uses STDIN and STDOUT on the terminal as before. So I get the idea, but I'm stuck again. Any further help would be appreciated.

      Thanks,
      Scott

        Just add AUTOLOAD to handle not implemented methods:
        sub AUTOLOAD {}
        Take a look in perltie to implement all the other methods if you really want to make a full IO redirection through tie.

        Here's a list of the other methods:

        sub PRINTF {} sub READ {} sub READLINE {} sub GETC {} sub WRITE {} sub FILENO {} sub STORE {} sub FETCH {} sub CLOSE {} sub DESTROY {}

        Graciliano M. P.
        "Creativity is the expression of the liberty".