in reply to Re^9: Please suggest a non-forking way to do this (OS: windows)
in thread Please suggest a non-forking way to do this (OS: windows)

Not quite

Are you saying the non-blocking script I posted didn't work for you? This slightly modified version using STDIN works fine, in a non-blocking manner for me on linux. Is your error coming on a Windows platform? If thats so, nothing I can do, except encourage people to switch to a real operating system, instead of a game platform. :-)

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(-background => 'gray50'); my $text = $mw->Scrolled('Text')->pack(); my $pid; my $startb = $mw->Button( -text => 'Start', -command=> \&work, )->pack(); my $count = 0; my $label = $mw->Label(-textvariable=>\$count)->pack(); my $testtimer = $mw->repeat(500, sub { $count++} ); my $stopb = $mw->Button( -text => 'Exit', -command=>sub{ kill 9,$pid; exit; }, )->pack(); MainLoop; ##################################### sub work{ $startb->configure(-state=>'disabled'); use Fcntl; #long 10 second delay between outputs # $pid = open (my $fh, "top -b -d 10 |" ) or warn "$!\n"; fcntl(\*STDIN, F_SETFL, O_NONBLOCK) || die "$!\n"; # Set the non-block flags my $repeater; $repeater = $mw->repeat(10, sub { if(my $bytes = sysread( \*STDIN, my $buf, 1)){; $text->insert('end',$buf); $text->see('end'); } } ); }

s far as I know, it's impossible to detect whether the pipe has data waiting.

On linux you can, see "perldoc -q waiting".


I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^11: Please suggest a non-forking way to do this (OS: windows)
by ikegami (Patriarch) on Sep 30, 2008 at 15:27 UTC

    This slightly modified version using STDIN works fine, in a non-blocking manner for me on linux.

    I just showed that your fcntl command doesn't work on Windows.

    Is your error coming on a Windows platform? If thats so, nothing I can do, except encourage people to switch to a real operating system, instead of a game platform. :-)

    Windows does have an equivalent to unix's file handles and select (events that can be tied to file handles and WaitForMultipleObjects), but Perl doesn't support them.

      For the sake of the original poster, would you know the names of the Win32 modules that implements the select function, and/or anything that relates to reading pipes?

      I'm not really a human, but I play one on earth Remember How Lucky You Are