RE: capturing output from running process crashes gtk2
- From: "Roderich Schupp (ext)" <Roderich Schupp ext BenQ com>
- To: "Ratcliffe, Jeffrey (Peters)" <Jeffrey Ratcliffe External eads com>, <gtk-perl-list gnome org>
- Subject: RE: capturing output from running process crashes gtk2
- Date: Wed, 2 Aug 2006 16:08:15 +0200
Right. Almost there. The following script works, but gives me
the warning "Name "main::WRITE" used only once: possible typo
at ./test_dialog3 line 23." If I replace \*WRITE with 0, then
I get the error message "open3: close(0) failed: Bad file
descriptor at ./test_dialog3 line 23".
How do I write it so as to avoid the warning?
Use lexical filehandles (instead of oldstyle global ones), like so:
my ($write, $read, $error);
my $pid = open3($write, $read , $error, "./test_scan" );
...
Glib::IO->add_watch(fileno($error), 'in', sub {
...
sysread $error, $line, 1024;
As for the problem with the real scanimage program mentioned by zentara:
- write some character to $write to make the scan continue
NOTE: make the $write handle autoflush, otherwise
print $write "X"
might not actually write someting into the pipe (that was created by
open3)
yet, but only when the internal buffer has filled up (you might get
lucky
with the character "\n" because the filehandle might be line-buffered
by default, but better to make sure)
- if you want to stop the scan, simply
close $write
- you should have add_watch for $error also look for "err" conditions
(esp. eof on $error when the scanimage process exits) and handle
them in the callback - see the IPC::Open3 man page how to reap
the sub process to avoid a zombie
Cheers, Roderich
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]