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

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
  • Comment on Re[3]: Modifying STDOUT and keeping control

Replies are listed 'Best First'.
Re: Re[3]: Modifying STDOUT and keeping control
by Anonymous Monk on Oct 14, 2002 at 20:11 UTC
    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
Re: Re[3]: Modifying STDOUT and keeping control
by Anonymous Monk on Oct 14, 2002 at 20:18 UTC
    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..