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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|