[sane-devel] parsing help output of scanimage there has got to be a better way?
jeff.sadowski at gmail.com
Mon Sep 18 19:28:23 UTC 2017
I am trying to design a web interface like phpsane (developer no longer
working on it)
It looks like he had issue also with parsing the help output as phpsane
didn't work for me.
I had created something like phpsane myself a while ago and was using it
until I upgraded and I lost my web interface.
I was looking if I had to create my own again or if something is out there.
I couldn't find anything so I went at creating my own again. I am really
satisfied with the way I do my php and having it spawn a separate php job
that runs in the background. I had originally customised mine for my
printer but now I wanted to make it more dynamic since I had to rebuild it
The extremely hard part is coming up with a way to parse the stdout of
Is there a good way to to this with regular expressions or something.
I have some ways I'm working on that I keep breaking up the string a bit at
a time but it seems exhausting coming up with a parser for pulling the
command line arguments and available options out of that.
Attached is the stdout output of my "scanimage -h"
My first approach was to go after every line that started with - or space -
As you can see in my attached output that approach won't work.
Any suggestions on how to start? Any suggestions on a place to share my
code with others?
I have just started using git on bitbucket for a class I am taking would
that be a good place?
-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
Usage: scanimage [OPTION]...
Start image acquisition on a scanner device and write image data to
Parameters are separated by a blank from single-character options (e.g.
-d epson) and by a "=" from multi-character options (e.g. --device-name=epson).
-d, --device-name=DEVICE use a given scanner device (e.g. hp:/dev/scanner)
--format=pnm|tiff file format of output file
-i, --icc-profile=PROFILE include this ICC profile into TIFF file
-L, --list-devices show available scanner devices
-f, --formatted-device-list=FORMAT similar to -L, but the FORMAT of the output
can be specified: %d (device name), %v (vendor),
%m (model), %t (type), %i (index number), and
-b, --batch[=FORMAT] working in batch mode, FORMAT is `out%d.pnm' or
`out%d.tif' by default depending on --format
--batch-start=# page number to start naming files with
--batch-count=# how many pages to scan in batch mode
--batch-increment=# increase page number in filename by #
--batch-double increment page number by two, same as
--batch-prompt ask for pressing a key before scanning a page
--accept-md5-only only accept authorization requests using md5
-p, --progress print progress messages
-n, --dont-scan only set options, don't actually scan
-T, --test test backend thoroughly
-A, --all-options list all available backend options
-h, --help display this help message and exit
-v, --verbose give even more status messages
-B, --buffer-size=# change input buffer size (in kB, default 32)
-V, --version print version information
Options specific to device `brother2:bus1;dev1':
--mode Black & White|Gray[Error Diffusion]|True Gray|24bit Color [24bit Color]
Select the scan mode
--resolution 100|150|200|300|400|600|1200|2400|4800|9600dpi 
Sets the resolution of the scanned image.
--source FlatBed|Automatic Document Feeder [Automatic Document Feeder]
Selects the scan source (such as a document-feeder).
--brightness -50..50% (in steps of 1) [inactive]
Controls the brightness of the acquired image.
--contrast -50..50% (in steps of 1) [inactive]
Controls the contrast of the acquired image.
-l 0..215.9mm (in steps of 0.0999908) 
Top-left x position of scan area.
-t 0..355.6mm (in steps of 0.0999908) 
Top-left y position of scan area.
-x 0..215.9mm (in steps of 0.0999908) [215.88]
Width of scan-area.
-y 0..355.6mm (in steps of 0.0999908) [355.567]
Height of scan-area.
Type ``scanimage --help -d DEVICE'' to get list of all options for DEVICE.
List of available devices:
More information about the sane-devel