Filehandle that reads remsh output 
Author Message
 Filehandle that reads remsh output

I have a Perl script I'm playing with that tries to use a filehandle
to read output from a remsh command:

#!/usr/bin/perl
$| = 1;
open(MACHINES,"my_primary_machines");
   while($mach = <MACHINES>) {
   open(BDF,"remsh $mach bdf |");
      print "Looking at machine $mach\n";
      while($line = <BDF>) {
         print $line;
      }
   }

I expected that to remsh to the machine, execute the command,
and then print each line ouf output.  What it actually does is
remsh to the machine and sit there till I manually "exit" them
remsh, and THEN it does the bdf and closes...any ideas?

Walter



Sat, 19 Jul 1997 06:30:33 GMT  
 Filehandle that reads remsh output

Quote:
>I have a Perl script I'm playing with that tries to use a filehandle
>to read output from a remsh command:
>#!/usr/bin/perl
>$| = 1;
>open(MACHINES,"my_primary_machines");
>   while($mach = <MACHINES>) {
>   open(BDF,"remsh $mach bdf |");
>      print "Looking at machine $mach\n";
>      while($line = <BDF>) {
>         print $line;
>      }
>   }
>I expected that to remsh to the machine, execute the command,
>and then print each line ouf output.  What it actually does is
>remsh to the machine and sit there till I manually "exit" them
>remsh, and THEN it does the bdf and closes...any ideas?

You forgot to remove the newline from $mach.  Consequently you're
running two-line scripts, as in

        open(BDF, "remsh your_first_machine
                   bdf |");

In the shell, that's two commands.  First it runs remsh without
arguments (which runs rlogin).  After you logout from the remote
machine, bdf is run on your local machine.

By the way, remsh does unspeakable things to your keyboard.
If you're remsh'ing a command that doesn't take input, use
remsh's -n option.

If you don't close BDF, there'll be a zombie process until your
script terminates.

#!/usr/bin/perl
$| = 1;
open(MACHINES,"my_primary_machines");
   while($mach = <MACHINES>) {
   chop $mach;
   open(BDF,"remsh -n $mach bdf |");
      print "Looking at machine $mach\n";
      while($line = <BDF>) {
         print $line;
      }
   close BDF;   # don't leave a zombie
   }

--
Hope this helps,

HansM



Mon, 21 Jul 1997 21:01:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Inappropriate warning: Filehandle Symbol::GEN33 opened only for output

2. Using print statement output like a filehandle

3. capturing output of FILEHANDLE "| command"

4. Filehandle opened only for output

5. Print to output filehandle?

6. PERLFUNC: syswrite - fixed-length unbuffered output to a filehandle

7. PERLFUNC: printf - output a formatted list to a filehandle

8. PERLFUNC: print - output a list to a filehandle

9. PERLFUNC: syswrite - fixed-length unbuffered output to a filehandle

10. PERLFUNC: print - output a list to a filehandle

11. Lie: Filehandle Symbol::GEN33 opened only for output

12. HELP: multiple write statements to one output filehandle

 

 
Powered by phpBB® Forum Software