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".
In reply to Re^10: Please suggest a non-forking way to do this (OS: windows)
by zentara
in thread Please suggest a non-forking way to do this (OS: windows)
by cranky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |