in reply to Question about IPC::Open2

Hard to tell, but a couple of things hit me about possibilities here. First off, the sleep looks dangerous. That's because /my/application could simply fill up its output buffer, and you'd end up with it suspended until you empty it. So perhaps you want to find the current time, and then loop on HIS_OUT - after three seconds (or whatever), issue the quit, and keep looping. e.g.,

my $pid = open2(*HIS_OUT, *HIS_IN, "/my/application" ) || die $!; my $now = time(); # you may want something more precise, whatever. while (<HIS_OUT>) { chomp; do_something_to($_); if ($now and time - $now > 4) { print HIS_IN "quit\n"; $now = undef; # don't keep doing this. } }
The next thing that hits me is that this sounds like a reasonable use for alarm - set an alarm for 3 seconds, and in that alarm print the quit message, but still go directly into the while loop handling HIS_OUT in your normal codepath.

What really hits me is that you want an individual time-out on HIS_OUT. While select would probably be the low-level way to do this, I've found IO::Select to be much simpler. The concept is that you'll select to read from HIS_OUT with a timeout of, say, one second. If the select times out, then you issue your quit, and go back into the loop - this time it should exit because the filehandle closes from the other end. However, while this may be the right algorithm in C where you don't have things like closures, the alarm methods might be simpler in perl.

Good luck,