1
0
forked from pool/cups-backends
cups-backends/cups-pipe.pl

69 lines
1.1 KiB
Perl

#!/usr/bin/perl -w
#
# CUPS backend for printing to any program via pipe
#
# Copyright (c) 2003 SuSE Linux AG, Nuernberg, Germany.
#
# Author: Jiri Srain <jsrain@suse.cz>, 2003
#
$scheme = "pipe";
if (@ARGV == 0)
{
print "file $scheme \"Unknown\" \"Printing to any command via pipe\"\n";
exit 0;
}
# in case of wrong number of arguments: print usage hint
if (@ARGV != 5 && @ARGV != 6)
{
print STDERR "
Usage: pipe job-id user title copies options [file]
example for device-URI: 'pipe:/path/to/targetcommand'
Install a printqueue with 'lpadmin -p <pipe-printer-name>
-v pipe:/</path/to/targetcommand> -E
";
exit 1;
}
if (defined ($ARGV[5]))
{
$file = $ARGV[5];
}
else
{
$file = "-";
}
# get file to which the job is "printed" from device URI, so
# so that you can use this backend multiple times, for various
# "pipe" printers...
$uri = $ENV{"DEVICE_URI"};
$arg = $uri;
$arg =~ s/$scheme:(.*)/$1/;
$cmdln = "/bin/cat $file | $arg";
if ($> == 0)
{
$cmdln = "su -c \"$cmdln \" lp";
}
my $exit = system ($cmdln);
if ($exit != 0)
{
print STDERR "ERROR: Error occurred while executing $cmdln";
}
exit $exit >> 8;