I'm trying to write a network connecticity application that has, as one of the functions, the ability to run a console application with bidirectional data across a socket, much like having a forwarded interactive console.

This is ActiveState perl 5.8.8.816. This will be compiled with the PDK, so if it's possible to do this with very few modules, I'm all for it.

Of course, there are other things I want to do with this or I would simply use existing tools, but this is the piece that's breaking.
First, I thought I might be able to use
open2($socket,$socket, "cmd.exe");
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.
Then I tried a few other ideas:
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 doesn't work, because select always returns an empty list.

Then I tried:
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"; }
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.

Any thoughts on what I can do from here to hopefully get this working?

In reply to Win32 console polling by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.