# [tex-live] epstopdf does not propagate exit code

Heiko Oberdiek oberdiek at uni-freiburg.de
Mon Sep 14 01:52:49 CEST 2009

On Mon, Sep 14, 2009 at 01:30:49AM +0200, Reinhard Kotucha wrote:

> On 13 September 2009 Heiko Oberdiek wrote:
>
>  > On Sun, Sep 13, 2009 at 10:32:37PM +0200, Reinhard Kotucha wrote:
>  >
>  >> On 13 September 2009 T T wrote:
>  >>
>  >>  > I've noticed that epstopdf utility does not propagate exit code from
>  >>  > ghostscript (WinXP), so I can't detect GS failure. Any chance to fix
>  >>  > that?
>  >>
>  >> This is a known problem and I sent Gerben a patch already.  He said
>  >> that he was on leave and will reply later.  No other response so far.
>  >>
>  >> Here is the patch I sent him:
>  >>
>  >> --- epstopdf.pl	2009-07-20 02:59:05.000000000 +0200
>  >> +++ epstopdf.pl-new	2009-08-25 22:58:06.000000000 +0200
>  >> @@ -427,5 +427,6 @@
>  >>  close(IN);
>  >>  print OUT "\ngrestore\n" if \$BBCorrected;
>  >>  close(OUT);
>  >> +exit (\$?/256) if \$?;
>  >>
>  >>
>  >> The Perl variable \$? contains a 16 bit number, the most significant
>  >> byte contains the exit code.  Thus the division by 256.
>  >
>  > And ghostscript could be aborted by a signal (the lower 8 bits),
>  > example, see pdfcrop.
>
> I'm not sure if signal handlers always work reliably on Windows.  And
> they probably behave differently on MSYS.

I don't think it doesn't matter, if the OS ignores signals or
what signal is used exactly, if the ghostscript run fails because
of this. And this can be detected by \$?. (CTRL-C by the user is
probably the most relevant use case.)

> However, I looked into pdfcrop and found:
>
>    \$GS = "gswin32c" if \$^O =~ /cygwin/i;
>
> This is wrong.  Cygwin provides its own Ghostscript which is called "gs".
> I didn't check your other scripts.

It isn't wrong. Cygwin is installed on Windows and the Windows port
of ghostscript is gswin32c. Of course cygwin has its own port.
Thus the code above is just a guess, which ghostscript may be available.
It would be better to look for the binary to find ghostscript if
only one variant is available. (Also MikTeX has its own mgs ...)
On my system there are a dozen ghostscript versions available.
Therefore I have added switch --gscmd to let the user override the
guess of the script.

Of course I would appreciate a better algorithm to find ghostscript
on the various systems. However I don't have the time to deal
with this problem right now, I have to postpone it to end of October
or November.

Yours sincerely
Heiko <oberdiek at uni-freiburg.de>