Proclus has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks, I'm running traceroute with open(), trying to read from the filehandle with select() and sysread(). The idea is to get the output in a nonblocking fashion.

The code below works in my Linux box. But I cannot get select to read anything in Windows Vista ( Activestate 5.10 ).

I'm pretty sure that I'm doing something inherently wrong with select and then sysread().

Can you comment on the code below and provide some options? Why is it not working with Windows? Thanks!!
use strict; use IO::Select; use IO::Handle; use Time::HiRes qw(usleep); $| =1 ; my $pingout ; open($pingout, '-|', "tracert www.google.com"); if($pingout){ my $select = IO::Select->new(); $select->add($pingout); while (1) { print "loop\n"; my $line; if (my @ready = $select->can_read(0) ) { foreach(@ready){ $_->sysread($line, 2048); print $line,$/; } } usleep(100000); # 100 ms } }
------------------------------ "geneva will not marry you no matter how much you love Larry Wall." Geneva Wall

Replies are listed 'Best First'.
Re: open,select,sysread for non-blocking traceroute
by ikegami (Patriarch) on Jun 02, 2009 at 17:39 UTC
    select only works on sockets in Windows.
      Hmmmm. Thanks ikegami.
      Any idea about what I can use to get data from open()'ed filehandle without blocking the program?
      ------------------------------ "geneva will not marry you no matter how much you love Larry Wall." Geneva Wall
        Looks like I'm not alone. Looking through this now: http://www.perlmonks.org/?node_id=621058