in reply to tail pipe
G'day aquercus,
Welcome to the monastery.
I don't have perl running on any MSWin OSes; however, here's how I might have tackled this on a *nix OS. There may be sufficient here for you to adapt it to your OS. I've added some notes after the code as well as a sample run.
Here's the code (pm_test_tail_pipe.pl):
#!/usr/bin/env perl use strict; use warnings; use autodie qw{:all}; my $tail_cmd = 'tail -f ./pm_test_file_to_tail'; my @tail_captures; print '*** Start reading from $tail_pipe at ', time, "\n"; my $tail_pid = open my $tail_pipe, '-|', $tail_cmd; { local $SIG{INT} = sub { kill INT => $tail_pid if kill 0 => $tail_pid; waitpid $tail_pid => 0; }; while (<$tail_pipe>) { push @tail_captures, $_; } } print '*** Stop reading from $tail_pipe at ', time, "\n"; # Possibly process data captured, e.g. for demo only $_ = uc for @tail_captures; print '*** Captured via $tail_pipe:', "\n"; print for @tail_captures;
Notes:
Sample run:
| File to Tail | Tailing Process |
|---|---|
|
Assume some log file that already has some data
[terminated with Ctrl-D] |
|
|
External program starts appending data
|
|
|
Start tailing the file
|
|
|
External program appends more data
|
|
|
[terminate tailing with Ctrl-C]
|
|
|
External program still appending data
[External program terminated with Ctrl-D] |
|
|
Check final contents of tailed file
|
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: tail pipe
by aquercus (Initiate) on Jun 20, 2013 at 17:02 UTC |