No such thing as a small change | |
PerlMonks |
Re: Parsing from another program (stream)by Marshall (Canon) |
on Feb 28, 2022 at 23:46 UTC ( [id://11141720]=note: print w/replies, xml ) | Need Help?? |
First this is a cool application! I went to https://github.com/bemasher/rtlamr to get an idea of what you are doing. I didn't read everything, I just perused enough to get the general idea. I assume that you have started rtl_tcp and that it is running in the background somewhere. I further assume that when you start rtlamr in another command window that you get an output as shown at that URL. The syntax, "open $fh, '-|', $programName" should work as long as you have the path and file permissions correct (make sure execute permission is enabled). Make sure that rtlamr runs in a command window like the example at the URL. Replace this code.... With this: As you have correctly surmised, you will not get an EOF while reading the file handle associated with the radio receiver. Although I believe that killing the rtlamr process would cause an EOF, I don't recommend that you do that. The loop I show above is infinite - it will never end because there is no EOF. Most of the clock time will be spend just waiting at the while statement with essentially nothing happening otherwise (no CPU cycles for this program). It is possible to do "non-blocking" reads and come up with a scheme to decide that "all the data has been read that can be read at this time". However, that is messy and I don't recommend that. You can just leave the above program and rl_tcp running all the time. To do the analysis, you should have a 3rd program. In the analysis program, open the disk file that is being appended by the program above. You can read that filehandle, line by line and you will get an EOF when all of the data has been read. There is nothing wrong with reading a file that is being appended by another program. However, be aware that very rarely there is the possibility of a premature EOF - meaning that EOF will happen before a newline is encountered. You should allow for that. You can either throw this last line away or just restart the reading process by re-opening the file and reading the file from the beginning again (you just barely missed the last part of the last line).
So, by writing to an intermediate disk file, we solve the "there is no EOF" problem. The disk file will have an EOF when all the data that is currently in it has been read.
In Section
Seekers of Perl Wisdom
|
|