(I don't understand why you include "+" in the open mode - it allows your script to have read access as well as write access, but you don't seem to need that.)
If you know enough about the behavior of the other program, perhaps you can write a simple perl script to emulate how that program reads from a file, then use the perl script to see what happens when you run it at the same time as your sample P2 script.
I don't recall ever using named pipes in any serious way, so playing the the following two scripts was instructive for me:
Script for writing to pipe:
#!/usr/bin/perl use strict; use warnings; use POSIX 'mkfifo'; my $fifo = "/tmp/named.pipe"; unless ( -p $fifo ) { mkfifo( $fifo, 0666 ) or die $!; } while (1) { open( my $fh, '>', $fifo ); my $t = scalar localtime; warn "writing to fifo at $t\n"; print $fh "written at $t\n"; close $fh; sleep 2; }
Script for reading from pipe:
I noticed these behaviors:#!/usr/bin/perl use strict; use warnings; my $input = "/tmp/named.pipe"; die "$input is not really a named pipe\n" unless (-p $input); while(1) { my $t = scalar localtime; warn "opening input at $t\n"; open( my $p, "<", $input ) or die $!; $_=<$p>; print "got: $_" }
In this case, I can still start either writer or reader first, nothing happens till both are running, and then they both show continuous output every 2 seconds, but now if either one is stopped, then the other will also stop.#!/usr/bin/perl use strict; use warnings; my $input = "/tmp/named.pipe"; die "$input is not really a named pipe\n" unless (-p $input); my $t = scalar localtime; warn "opening input at $t\n"; open( my $p, "<", $input ) or die $!; while(<$p>) { $t = scalar localtime; print "reading at $t, got: $_" }
Other variations might be worth trying… but as moritz mentioned, we don't know enough yet about what you are actually trying to accomplish.
In reply to Re: How to clear named pipe to just have one line
by graff
in thread How to clear named pipe to just have one line
by techman2006
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |