in reply to reading output from another script
# monitor.pl while(<>) { if(/wantthis/) { dosomething($_); } if(/warning/) {dosomethingelse($_); } print; ## pass on the output }
# monitor.pl open(INPUT, "./script |") or die $!; while(<INPUT>) { # same as above if(/regex/) { dosomething($_); } print; } close INPUT;
Now add filteroutput(); above the rest of the script's normal code. It's self-monitoring.# adapted from Perl Cookbook sub filteroutput { return if my $pid = open(STDOUT, "|-"); die "cannot fork: $!" unless defined $pid; while(<STDIN>) { if(/regex/) { dosomething($_); } print; } exit; #exit forked monitoring process }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: reading output from another script
by Octavian (Monk) on Jul 24, 2003 at 13:48 UTC | |
by jmanning2k (Pilgrim) on Jul 24, 2003 at 14:39 UTC | |
by Octavian (Monk) on Jul 24, 2003 at 16:59 UTC | |
|
Re: Re: reading output from another script
by Octavian (Monk) on Jul 24, 2003 at 16:32 UTC |