in reply to Modifying STDOUT and keeping control

Some relevant code might be helpful, i can't see what you're actually doing.

... program I've called with back ticks ...

Well the `backticks` return the ouput of the program, you can modify this output and then print it to STDOUT. Where's the problem?

Did you consider using open() to fork off telnet and process its output line by line and just in time? What do you mean with "loosing control of telnet"?

--
http://fruiture.de
  • Comment on Re: Modifying STDOUT and keeping control

Replies are listed 'Best First'.
Re: Re: Modifying STDOUT and keeping control
by Anonymous Monk on Oct 14, 2002 at 19:34 UTC
    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?

      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. :-)

      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.

        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..