Gtk2::Helper or Glib::IO event watcher problem




I need to write a perl script that would act as a frontend to another perl 
script and show its console output in a non-locking "realtime" manner. The 
backend script does a lengthy job and outputs some messages via print 
"message\n"; . I want these messages to be received, parsed and visualised 
by the frontend.

It does sound like a FAQ, but unfortunately the FAQ did not help me.

I took this piece of code from there but it works strangely: 


    open(IN, q^perl -e '$|++; for($i=0;$i<10;$i++) { $sum+= $i; print "Line $i: sum = $sum\n"; sleep 1;}'|^)
       or die "Failed running perl subprocess\n";

    my $tag;
    $tag = Gtk2::Helper->add_watch ( fileno(IN), 'in', sub {
        if (eof(IN)) {
        Gtk2::Helper->remove_watch ($tag);
        close(IN);
        }
        else {
        my $line = ;
        $buffer->insert($buffer->get_end_iter,
                        $line);
        }

        return 1;
    });

    Gtk2->main;


The problem is that the event callback seems to be triggered only once 
when EOF is received. I need it to occur either when a newline appears 
in the pipe (backend prints "\n") or by every single character. I have 
no clues on how to make the watcher act as needed and my frontend draw 
messages one-by-one instead of one bulk line after an hour long wait.

BTW:
Analogous code (using Perl::Tk) works nicely for me.

        open(H, "perl SVGTEXT.pl \"$dirpath\" -|") or die "Nope: $!";
        $mw->fileevent(\*H, 'readable', [\&showlog, $logbox]);

Do I (or the FAQ) miss something important in the above example?
Is there any other way to implement event based pipe reading with Perl::Gtk2?



In fact, I need this to write several different frontends.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]