Hi, someone on the Gtk2-perl maillist got me thinking about how to run my scanner thru IPC. In the following code, my attempts to send a Control-d to the WRITE filehandle, piped to scanimage, never seems to cancel the scan. It accepts it as an Enter and continues the scan. I've uncommented the method shown by expect, using "\cd", but none of them work.
Does anyone know how to force that control-d to go thru the WRITE pipe?
I know I could just kill the $pid, but the control-d works from the command-line operation of scanimage, and I would like to know why it dosn't go thru IPC.
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
use Tk;
my $mw=tkinit;
my $start_but = $mw->Button(-text => 'Start Scan',
-command => \&start_scan)->pack();
my $cancel_but = $mw->Button(-text => 'Cancel Scan',
-command => \&stop_scan)->pack();
MainLoop;
###################################
sub start_scan{
# do a 'scanimage -L ' for your list
my @options = ( '-d umax:/dev/scanner',
'-b',
'--format=tiff',
'--batch-count=3',
'--batch-prompt',
);
#interface to scanimage
my $pid = open3(\*WRITE, 0 ,\*ERROR, "scanimage @options" );
$mw->fileevent('ERROR', 'readable' => \&collect_stderr);
}
###############################################################
sub collect_stderr {
my $err = <ERROR>;
print $err;
}
###############################################################
sub stop_scan{
# print WRITE chr(4),"\n";
# print WRITE "\x04\n";
print WRITE "\cd";
# print WRITE "\004\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.