One way:
use threads qw( async ); use Thread::Queue qw( ); my $q = Threads::Queue->new(); async { while (<STDIN>) { $q->enqueue(...); } $q->enqueue(...); }; async { while (<$fr_child_pipe>) { $q->enqueue(...); } $q->enqueue(...); }; while (defined(my $item = $q->dequeue())) { ... }
Another solution would be to create socket pairs (which are selectable), and have threads that simply convert the pipes into sockets. That would allow you to use existing code.
use threads qw( async ); use Win32::Socketpair qw( winsocketpair ); my ($fr_parent_sock, $fr_parent_sock_writer) = winsocketpair(); async { print($fr_parent_sock_writer $_) while <STDIN>; close($fr_parent_sock_writer); }; my ($fr_child_sock, $fr_child_sock_writer) = winsocketpair(); async { print($fr_child_sock_writer $_) while <$fr_child_pipe>; close($fr_child_sock_writer); }; ... select $fr_parent_sock and $fr_child_sock ...
(You could avoid the second thread by tying the socket directly to the child's STDOUT.)
Update: Fleshed out the code for the second solution, and added a link to the module.
In reply to Re: Alternative for Select for pipes in Windows?
by ikegami
in thread Alternative for Select for pipes in Windows?
by matematiko
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |