capturing output from running process crashes gtk2

I am new to Perl and gtk2-perl, but not to awk, C, etc, or to GUI programming.

I am trying to use my scanner via a gtk2-perl script. As I can't find a Perl wrapper for sane, I am having to 
use scanimage.

scanimage writes info about which page is being scanned to stderr. I'd like to capture this, but my various 
attempts crash gtk2.

I've reduced the code to the test example below. Can anyone give me any pointers on how to achieve what I 
want (or give me a Perl wrapper for sane)?



#!/usr/bin/perl -w

use strict;
use Gtk2 -init;

my @output;

my $script = <<END;
while [ 0 ]
 let ++page
 echo "Scanned page \$page. (scanner status = 5)" > "/dev/stderr"
 sleep 5

open SCRIPT, "> test_scan" or die "Can't open script";
print SCRIPT $script;
close SCRIPT;
chmod 0755, "test_scan"; # u+rwx,go+rw

#system ("./test_scan &");

# output = `./test_scan 2>&1 1>/dev/null &`;
# output = `./test_scan &`;

system ("./test_scan 2>stderr.out &");

my $dialog = Gtk2::Dialog->new ("Scanning...", undef,
                                'gtk-cancel' => 'cancel');
my $label = Gtk2::Label->new ("Scanning...");
$dialog->vbox->add ($label);

$dialog->signal_connect (response => sub { $_[0]->destroy;
                                           local $SIG{HUP} = 'IGNORE';
                                           kill HUP => -$$;
                                           print @output;

open READHANDLE, "stderr.out" or die "Can't open file for reading: $!";
Glib::IO->add_watch(fileno(READHANDLE), 'in', sub { while (<READHANDLE>) {
                                                     print "Found \"$_\"";
                                                    return 1;


exit( 0 );

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