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 TailTailing Process

Assume some log file that already has some data

$ cat > pm_test_file_to_tail line 1 line 2 line 3

[terminated with Ctrl-D]

 

External program starts appending data

$ cat >> pm_test_file_to_tail line 4 line 5
 
 

Start tailing the file

$ pm_test_tail_pipe.pl *** Start reading from $tail_pipe at 1371707519

External program appends more data

line 6 line 7
 
 

[terminate tailing with Ctrl-C]

^C*** Stop reading from $tail_pipe at 1371707542 *** Captured via $tail_pipe: LINE 1 LINE 2 LINE 3 LINE 4 LINE 5 LINE 6 LINE 7

External program still appending data

line 8 line 9

[External program terminated with Ctrl-D]

 

Check final contents of tailed file

$ cat pm_test_file_to_tail line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9
 

-- Ken

Replies are listed 'Best First'.
Re^2: tail pipe
by aquercus (Initiate) on Jun 20, 2013 at 17:02 UTC

    Thanks very much for this detailed response but unfortunately the problem remains the same: Since the "tail" available on windows is the MS toolkit program, the output from it continues to be displayed in a command window it creates, and is not captured in your perl program.