Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: How to clear named pipe to just have one lineby graff (Chancellor) |
on Feb 10, 2014 at 06:32 UTC ( [id://1074196]=note: print w/replies, xml ) | Need Help?? |
The way you've written your sample perl script (P2) for writing to the fifo, there could never be more than one line in the pipe; the open statement, having one ">" in the mode flag, always truncates the file on opening. Then you write one line and close the fifo.
(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:
Script for reading from pipe: I noticed these behaviors:
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. 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 Section
Seekers of Perl Wisdom
|
|