Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
And Select on the $output and network socket, waiting for an error. I _hoped_ this would dup the socket and Just Work. This, of course, didn't work, or I wouldn't be posting here.open2($socket,$socket, "cmd.exe");
Which doesn't work, because select always returns an empty list.if (my $client = $server->accept( )) { open2($output,$input, "cmd /k"); $select->add($client); $select->add($output); } while(1) { foreach my $current_socket($select->can_read()) { my $data; $current_socket->read($data, 10,0); die unless $data; print $data, "\n"; } }
Which I had hoped would at least print both streams. $output blocks, though, cannot be selected on, and, as far as I can tell, cannot be modified by FCntl to set it to non-blocking.my $select = IO::Select->new( ); if (my $client = $server->accept( )) { open3($input,$output, undef, "cmd.exe"); $select->add($client); } $output->blocking(0); #fcntl($output, F_SETFL(), O_NONBLOCK()); while(1) { foreach( my ($current_socket) = $select->can_read(.5)) { last unless $current_socket; my $data; $current_socket->sysread($data,10,0); die unless $data; print $data, "\n"; } #we hit the timeout, so check the terminal for new data $output->sysread($data, 10, 0); print $data, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32 console polling
by salva (Canon) on Mar 29, 2006 at 13:26 UTC | |
by TheDauthi (Sexton) on Mar 29, 2006 at 14:22 UTC |