I can definitely change the buffering on the other application and that helps a bit.
As for the non-blocking, I thought non-blocking allowed a read to complete even when there was no data. If there was no data, I thought either EOF or EAGAIN or something was set. The example above can be changed to this to get it working in linux and loop as fast as possible.
use IO::Handle;
use Timer::HiRes qw(usleep);
print "before the pipe\n";
sub getpipe {
my $hash2 = shift;
print( "starting yes.pl " . time() . "\n" );
$hash2->{pid} = open( $hash2->{stdout}, "/usr/bin/perl yes.pl |") o
+r die;
$hash2->{buffer} = "";
$hash2->{stdout}->blocking(0);
sleep( 1 );
return $hash2->{pid};
}
my $hash = {};
getpipe($hash);
my $fh = $hash->{stdout};
print( "pipe created\n" );
my $count = 0;
while( 1 ) {
my $data = <$fh>;
if( $data != "" ) {
print "got from pipe: $data";
}
print( "." );
usleep( 10000 );
}
print( "done\n" );
I will try to post the script externally and provide a link so you understand what I'm trying to do a little better. To answer a couple of your questions about threads/processes, I'm really using both. I start the thread/process by calling fork. So in Linux, I understand that I'm using the true fork command. In Windows, I'm using the pseudo fork that is really thread when you get to the bottom of things. Which one I use doesn't matter. I just need a separate branch of execution so the parent script can continue doing its normal thing while my branch of execution handles the external processes. Thats probably an ignorant statement but that's why I'm posting :)
I've found another perl script that sounds like what I'm doing: logtail. I believe the basic idea is the same. I need to review the code more to see what they have done.
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, 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, 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.
|
|