[cups.general] Problems writing a simple backend

Johannes Meixner jsmeix at suse.de
Thu Dec 7 02:16:31 PST 2006


Hello,

On Dec 5 12:59 Neil Simmons wrote (shortened):
> I have a program that generates text strings which are meant to go to a
> printer but I want to use the CUPS to do something a bit more useful with
> them. To this end I intend to write a simple backend...

Do you really need a new backend or only a special filter?
See "man backend" and "man filter" and have a look at
http://en.opensuse.org/SDB:CUPS_in_a_Nutshell
to distinguish between backend and filter and note
the so called "System V style interface script".

If you really need a new backend, here a very simple example
how to send data to the first parallel port with everything
hardcoded (and a unlikely but possible race):
------------------------------------------------------------------
#! /bin/bash
# see the "CUPS Software Programmers Manual":
# "Writing Filters" and "Writing Backends"
# and see the man page "man backend".

# debug info in /var/log/cups/error_log
set -x

# output "Device Discovery" information on stdout
if test "$#" = "0"
then
  echo 'direct lp0:/dev/lp0 "Unknown" "lp0 Printer"'
  exit 0
fi

# have the input at fd0 (stdin) in any case
if test -n "$6"
then
  exec <"$6"
fi

# infinite retries to access the device
until cat /dev/null >/dev/lp0
do
  echo 'INFO: cannot access /dev/lp0 - retry in 30 seconds' 1>&2
  sleep 30
done
echo 'INFO: sending the data to /dev/lp0' 1>&2

# forward the data from stdin to the device
if cat - >/dev/lp0
then
  echo 'INFO:' 1>&2
  exit 0
else
  echo 'ERROR: failed to send the data to /dev/lp0' 1>&2
  exit 1
fi
------------------------------------------------------------------
Save it as /usr/lib/cups/backend/lp0
Set read and execute permissions accordingly.
Restart the cupsd.
Verify that the new backend is shown in "lpinfo -v".
Set the DeviceURI of the queue using
lpadmin -p <queue> -v lp0:/dev/lp0


Kind Regards
Johannes Meixner
-- 
SUSE LINUX Products GmbH, Maxfeldstrasse 5      Mail: jsmeix at suse.de
90409 Nuernberg, Germany                    WWW: http://www.suse.de/





More information about the cups mailing list