capturing output from running process crashes gtk2
- From: "Ratcliffe, Jeffrey (Peters)" <Jeffrey Ratcliffe External eads com>
- To: "'gtk-perl-list gnome org'" <gtk-perl-list gnome org>
- Subject: capturing output from running process crashes gtk2
- Date: Tue, 1 Aug 2006 10:30:25 +0200
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)?
Thanks
Jeff
#!/usr/bin/perl -w
use strict;
use Gtk2 -init;
my @output;
my $script = <<END;
#!/bin/bash
while [ 0 ]
do
let ++page
echo "Scanned page \$page. (scanner status = 5)" > "/dev/stderr"
sleep 5
done
END
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,
'destroy-with-parent',
'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;
Gtk2->main_quit;
});
$dialog->show_all;
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;
});
Gtk2->main;
exit( 0 );
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]