I am trying to write a piece of code that will look at a named pipe and move on if there is nothing to read from the pipe. I am using "select" and "vec" examples straight from the documentation (which honestly is leaving me a little confused). Obviously I am doing something wrong here and any insight is greatly appreciated.
Here is my code :
#!/usr/bin/perl -w
use strict;
my $FiFo='/opt/WFmon/logs/cpu.comm';
my $read='';
my $timeout=1;
my ($nfound);
open(FIFO, "<$FiFo") || warn "cannot open fifo\n";
vec($read, fileno(FIFO), 1) = 1;
$nfound = select($read, undef, undef, $timeout);
if($nfound){
if(vec($read, fileno(FIFO), 1)){
print "here - $nfound\n";
}
else{
print "not here - $nfound\n";
}
}
else{
print "nothing\n";
}
close(FIFO);
This works in the sence that when I copy/print/echo a string to the pipe (/opt/WFmon/logs/cpu.comm), the script
proceeds to the first "if" statement. Otherwise, the script just hangs there waiting for the pipe to complete and never times out.
Thank you!
Bryan
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.