(no subject)




Hello again.


My problem today is, that i want to show to output of a shellscript in a
Gtk2::Texview. To start the script i'm using the following.

        my $fh = new IO::Pipe;
        $fh->reader("./print_to_stdout.sh");

        my $helper_tag = Gtk2::Helper->add_watch(fileno $fh, 'in',sub{
            &watch_callback($fh)
            });

The script looks as follows:

        #!/bin/bash

        printf "bloedsinn !\n"
        sleep 1
        printf "GFIS_STATUS Eine Gui status Meldung 1\n"
        sleep 1
        printf "GFIS_STATUS Eine Gui status Meldung 1.6\n"
        sleep 1
        printf "GFIS_WARNING Eine Gui Warning Meldung 2\n"
        sleep 1
        echo "GFIS_STATUS Eine Gui status Meldung 3 "
        sleep 1
        echo "GFIS_WARNING Eine Gui Warning Meldung 4"
        #sleep 1
        echo "noch mehr bloedsinn !\n"
        echo
        echo "GFIS_STATUS Eine Gui status Meldung 5"
        #sleep 1
        echo "GFIS_WARNING Eine Gui Warning Meldung 6"
        #sleep 1
        echo "GFIS_STATUS Eine Gui status Meldung 7"
        #sleep 1
        echo "GFIS_WARNING Eine Gui Warning Meldung 8"
-------------------------------------------------------

The script will have more functionality than this example of course.
As you can see I tried to run the script with sleeps between the prints/echos and without them.
When i run it with the sleep commands everything looks fine, but if i omit the sleeps, my callback is't 
called any more.

So here are my questions.
-> Can a avoid that the echos/printfs are ignored by the Gtk2::Helper?

-> If not, is there another possibility to get the output of a shell script to a Gtk2::textview or another 
text viewing widget?

-> And last: Is it possible to watch a file and run a callback everytime a line is appended to the file? I 
tried to do so with a
Gtk2::Helper, but ended up with 100% CPU consumption becaus the callback was called everytime it was save to 
read the file.



This is my callback function. As you can see i want to display GFIS_WARNINGS in another color/style than 
GFIS_STATUS messages.
All other messages sould be ignored.
-------------------------------------------------
sub watch_callback{
    print "status callback called\n";
    my ($fh) = @_;

#    my @lines = $fh->getlines;
#    print @lines;

    my $line;
    $fh->sysread($line,1000);
    chomp $line;
    print $line ."\n";
    if($line){
        if($line =~ /^GFIS_STATUS/){
            $line =~ s/GFIS_STATUS//;
            $line =~ s/^\s+//g;
            $status_buffer->insert_with_tags_by_name (($status_buffer->get_end_iter()), $line, 'status');
            $status_buffer->insert_with_tags_by_name (($status_buffer->get_end_iter()), "\n", 'status');
        }
        elsif($line =~ /^GFIS_WARNING/){
            $line =~ s/GFIS_WARNING//;
            $line =~ s/^\s+//g;
            $status_buffer->insert_with_tags_by_name (($status_buffer->get_end_iter()), 'WARNING: ', 
'warning');
            $status_buffer->insert_with_tags_by_name (($status_buffer->get_end_iter()), $line, 'warning');
            $status_buffer->insert_with_tags_by_name (($status_buffer->get_end_iter()), "\n", 'warning');
        }       
        else{
            print "just a message\n";
        }
    }
    else{
        1 while wait != -1 ; 
        print "remove helper\n";
        Gtk2::Helper->remove_watch($helper_tag);
    }
    
    return TRUE;
}
------------------------------------


Thanks again for your help!


Regards
Josef



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