I'll answer some of the points you brought up first so you can point out any flaws in my thinking:
- I'm using the non-blocking because I have a thread that executes a requested command that should only take a few milliseconds. It then reads the output pipes from all my external applications and stores whatever it read into a buffer. If there isn't anything on the pipe that doesn't matter, I just continue and service the next request that may/may not be waiting. Select is never used so I didn't see this as an issue.
- The only signal I need is to tell the process to die. I've been using SigKill since I just want the forked executable to die. This seems to work in Windows and Linux.
- Thank you for the info on open. I thought the open( fh, "cmd |") ran in the foreground. I've switched to using that and it has cut out quite a bit of code. It also seems to work even better for killing the process. I'm still using sigkill since I don't know of a better way to do it in perl. Suggestions?
- The goal of the module, briefly addressed in the first point, is to provide an instance of the module that can start another process/thread/etc. The two processes will communicate with each other in a command/result xml format (all commands come from the instantiated module and are sent to the child process). The child process is the responsible for servicing those requests which includes starting up additional cli programs and buffering their output. The buffer will be regularly checked for errors and when the parent process requests the errors, they are passed back up. I hope that explains things.
From what I've read POE might have a been something to look at but I need this done sooner than later and I already have this module working in Linux... Windows is always the problem (jab). Plus I would like to get a better understanding of the inner workings of perl
The last problem I seem to be fighting is that when I run the code to set a pipe as nonblocking, it isn't really nonblocking. I seem to get a chunk of data every 15 seconds or so on Win2k3 using this code:
pipetest.pl
use IO::Handle;
print "before the pipe\n";
sub getpipe {
my $hash2 = shift;
$hash2->{pid} = open( $hash2->{stdout}, "c:\\perl\\bin\\perl.exe ye
+s.pl |") or die;
$hash2->{buffer} = "";
$hash2->{stdout}->blocking(0);
sleep( 3 );
return $hash2->{pid};
}
my $hash = {};
getpipe($hash);
my $fh = $hash->{stdout};
print( "pipe created\n" );
while( <$fh> ) {
print "got from pipe: $_";
sleep( 1 );
}
print( "done\n" );
yes.pl
while( 1 ) {
printf "%s yes\n", time();
sleep( 1 );
}
sample output:
got from pipe: 1226094472 yes
1226094473 yes
1226094474 yes
1226094475 yes
1226094476 yes
1226094477 yes
1226094478 yes
1226094479 yes
1226094480 yes
1226094481 yes
1226094482 yes
1226094483 yes
1226094484 yes
1226094485 yes
1226094486 yes
1226094487 yes
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.
|
|