On Sun, Apr 12, 2009 at 14:14, Michael Alipio <daem0n...@yahoo.com> wrote: > > Hi, > > I have a program that constantly displays values on the screen. The program > 'ping' for example. > > What I'd like to do is watch the output and as soon as i see some values, i > would do something. For example, as suppose when pinging a host I would > constantly get a reply. however, if I remove the network cable, of my pc, I > would start seeing host unreachable or something. As soon as I see this > message, I would like to do something. This is how I want to do this > (executing the program once and watching the output). I could probably run > ping every one second and check the output of each execution, however, that > is not how I want to do it. The program I will be running has to be run only > once, like for example the 'top' program. > > Any idea how to accomplish this? snip
Programs like ping that output a stream of information are easy to work with: ping wonkden.net | perl -ne 'print "I saw $_"' Perl defaults to a line buffered mode, so if your the program you want to watch outputs lines, then you just need a loop watching stdin (as above). To use top, you must put it in logging mode OS X top -l 0 | perl -ne 'print if /firefox/' Linux top -b | perl -ne 'print if /firefox/' -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/