in reply to Re: Modifying STDOUT and keeping control
in thread Modifying STDOUT and keeping control

I have an script that works as an interactive menu, some of the choices require the script to telnet to a remote host for the user to login to and complete a task, when they are done, it takes them back to the menu. What I'm trying to do is prevent the user from seeing this:
Trying 192.168.1.1... Connected to 192.168.1.1. Escape character is '^]'.
Or at least the ip address, when the script calls 'telnet 192.168.1.1'.

Does this make more sense?

Replies are listed 'Best First'.
Re: Re: Re: Modifying STDOUT and keeping control
by bart (Canon) on Oct 14, 2002 at 21:02 UTC
    I think I would still use Net::Telnet, and build an interactive shell into your script that passes on the user entered data on via Net::Telnet to the remote shell. See PPM on ActivePerl and CPAN (the module) for examples of what I'm thinking of. Also check out the module Term::ReadLine, which modern versions of CPAN.pm use, to write the command line interface for this side.

    Oh, look, no code. But you didn't provide any code either, so I won't feel bad about it. :-)

Re[3]: Modifying STDOUT and keeping control
by fruiture (Curate) on Oct 14, 2002 at 19:42 UTC
    Does this make more sense?

    No, i still can't find any code in your post. What do you mean with "call" when you say "the script calls 'telnet ...'"?

    Maybe you want to have a look at Expect, but I'm still just guessing.

    --
    http://fruiture.de
      Check it:
      #!/usr/bin/perl -w use strict; # Example script, simmilar to the one I'm writing.. menu(); sub menu { my @menu = ( [ 1 => 'Go' ], ); my %call = ( 1 => \&go, ); system("clear"); print " ", "$_->[0]. $_->[1]\n" for @menu; print "Enter Selection:"; chomp( my $answ = <STDIN> ); my $sub = $call{$answ} or err(); $sub->(); } sub go { # This is where the telnet call gets made. system("telnet", "192.168.1.1"); # Currently spawns shell command # my $var = `telnet 192.168.1.1' # This will save output to $var # So I can edit the output. system("clear"); menu(); } sub err { print "Valid Selection Not Entered!\n"; menu(); }
      I want the command to run with my modified output so the user can't see that it is telnetting to 192.168.1.1.

      The output can be modified easily enough using s/192.16.1.1//, But I can't seem to figure out how to make the user see the output I desire, while it's executing the telnet command.

        Well, the relevant code is:

        system('telnet' , '192.168.1.1');

        As `perldoc -f system` tells you, system() forks off a child, waits for it to exit and then returns to your program. `perldoc perlop` tells us that qx// does the same, but catches the stdout of the command and returns it (exit status should be in $? anyways). So I can't see why you cannot use qx//...

        my $var = `telnet 192.168.1.1`; $var =~ s/192.168.1.1//; print $var;

        update: oops, code tag typo, thanks Aristotle.

        --
        http://fruiture.de
      This snippet:
      open(PIPE, "telnet 192.168.1.1 |") or die $!; while (<PIPE>) { $_ =~ s/192.168.1.1//; print $_; }
      Does what I want, but it hangs after printing what it has, it doesn't continue to the login screen..