http://www.perlmonks.org?node_id=1073998


in reply to How to clear named pipe to just have one line

I don't think it's possible; if you read from a (named) pipe, its content is gone. So you can't read to check how much is in there.

Usually you don't need it either, since named pipes are buffered, and once the buffer is full, writing to it blocks. And, more to the point, you shouldn't even care how much is in the pipe; pipes are there to abstract that away.

What problem are you actually trying to solve? It could be an XY Problem.

Replies are listed 'Best First'.
Re^2: How to clear named pipe to just have one line
by techman2006 (Beadle) on Feb 08, 2014 at 13:22 UTC

    Basically there are two unrelated processes say P1 (A C program) and P2(a Perl script). Now P2 is running and is output some data to stdout. Now P1 will come at regular interval to read such data.

    As these are unrelated processes. So I was thinking to use named pipe. Now process P1 want to read only one line which is output from process P2. As it continuously generates output we want to truncate the data so that process P1 don't read redundant data.

    Any thoughts how to solve this problem.

        As process P1 is an server which is multithread and one of thread will try to read status from process P2. So process P1 will not have way to capture stdout of process P2.