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

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

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.