For Quality purpouses, zentara 's mail on Friday 30 January 2004 16:22 may 
have been monitored or recorded as:

Hi, 

neat trick! Great.
However, I have a, well, couriosity?

My script looks pretty much the same, except the print in &dosomething
(since it is acctually your script:-))

> Here is a set of programs, that do what you want.
> ######################################################
> #!/usr/bin/perl -w
> use strict;
> use Tk;
> my $mw = new MainWindow;
>
> my $listbox = $mw->Scrolled("Listbox", -scrollbars => "osoe",
>     -height => 5,
>     -selectmode => "multiple")
>     ->pack(-side => "left");
>
> my $start = $mw->Button( -text => 'Start', -command => \&start )->pack;
> $mw->Button( -text => 'Exit',  -command => \&exit )->pack;
>
>
> #start external command to pipe
> sub start {
>     $start->configure(-state => 'disabled');
>     open(C, "./read-own-stdout-piper 2>&1 |") or warn $!;
> $mw->fileevent( \*C, 'readable', \&doSomething );
>
> }
>
> sub doSomething {
>     if ( eof(C) ) {    # Child closed pipe
>           close(C);      # Close parent's part of pipe,
>                         # filevent is cancelled as well
>           wait;          # Avoid zombies
>     return;
>     }
>     my $text = <C>;    # Get text from child and put it into listbox
>     print $text;              #only diffeerence.
       chomp($text);
>     $listbox->insert( 'end', 'Got: ' . $text );
>     $listbox->see('end');
> }
>
> MainLoop;
>
> __END__
> ##############################################


and the called script looks different (but prints to STDOUT and has a $|++ for 
flush.

When I call the GUI from a command prompt opend under X I should see two 
parallel outputs, one in the terminal and one in the listbox, right.

I do see these outputs on both, but the one in the listbox  is way slower than 
the one to the console. However, the relation seams to be random (ie there is 
no, say constant 5 line adtvantage).
I also tried the 
tie @array, "Tk::Listbox", $listbox in &start and only call 
$listbox->see('end') in &dosomething with the result, that I get to see the 
whole output in the listbox at once and only when the callled script is 
finished.

Any Idea?

Thanks a lot, 
Wolf


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to