summaryrefslogtreecommitdiff
path: root/foomatic-gswrapper.in
diff options
context:
space:
mode:
Diffstat (limited to 'foomatic-gswrapper.in')
-rw-r--r--foomatic-gswrapper.in39
1 files changed, 29 insertions, 10 deletions
diff --git a/foomatic-gswrapper.in b/foomatic-gswrapper.in
index da0c29a..e6b1049 100644
--- a/foomatic-gswrapper.in
+++ b/foomatic-gswrapper.in
@@ -25,19 +25,32 @@ my $execpath = "@EXECPATH@";
$execpath = $conf{execpath} if defined(%conf) and defined $conf{execpath};
$ENV{'PATH'} = $execpath;
+# Check whether we have a GhostScript version with redirection of the
+# standard output of the PostScript programs via '-sstdout=%stderr'
+my $gswithstdoutredirection = 0;
+if (`$gspath -dQUIET -dPARANOIDSAFER -dNOPAUSE -dBATCH -dNOMEDIAATTRS -sDEVICE=pswrite -sstdout=%stderr -sOutputFile=/dev/null -c '(hello\n) print flush' 2>&1` =~ /hello/) {
+ $gswithstdoutredirection = 1;
+}
+
grep (m!\-sOutputFile=\-!
&& do {
- # Send the job to fd 3; errors will be on 2(stderr) and job
- # ps program interpreter output on 1(stdout).
- $_ = '-sOutputFile=/dev/fd/3';
+ # If GhostScript does not support redirecting the standard output
+ # of the PostScript program to standard error with
+ # '-sstdout=%stderr', sen the job output data to fd 3; errors
+ # will be on 2(stderr) and job ps program interpreter output on
+ # 1(stdout).
+ $_ = ($gswithstdoutredirection ?
+ '-sOutputFile=%stdout' : '-sOutputFile=/dev/fd/3');
# quoted properly below...
}, @ARGV);
-grep (((m!^\-$!) || (m!^\-_$!))
- && do {
- # Get the input from fd 0.
- $_ = "/dev/fd/0";
- }, @ARGV);
+if (!$gswithstdoutredirection) {
+ grep (((m!^\-$!) || (m!^\-_$!))
+ && do {
+ # Get the input from fd 0.
+ $_ = "/dev/fd/0";
+ }, @ARGV);
+}
# Turn *off* -q (quiet!); now that stderr is useful! :)
my @myargs = grep (! m!^\-q$!, @ARGV);
@@ -54,8 +67,14 @@ my $args = "'" . join("' '", @myargs) . "'";
# Execute Ghostscript, with both job and gs errors on stderr, and job
# output on stdout...
-print STDERR "foomatic-gswrapper: $gspath $args 3>&1 1>&2\n";
-exec "$gspath $args 3>&1 1>&2";
+if ($gswithstdoutredirection) {
+ $args = "'-sstdout=\%stderr' $args";
+ print STDERR "foomatic-gswrapper: $gspath $args\n";
+ exec "$gspath $args";
+} else {
+ print STDERR "foomatic-gswrapper: $gspath $args 3>&1 1>&2\n";
+ exec "$gspath $args 3>&1 1>&2";
+}
die "Failed to execute Ghostscript?!";