6

I have just updated to MiKTeX 2.9

I am using Emacs and I run pdflatex --shell-escape -interaction=nonstopmode "\input" Instructions.tex

pdfcrop gives me the following error

PDFCROP 1.33, 2012/02/01 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Cannot call ghostscript ("C:\Program Files   (x86)\gs\gs8.71\bin\gswin32c.exe")!

so I tried to call pdfcrop manually:

C:\>pdfcrop  --margins 10 --debug Instructions-autopp.pdf s.pdf
PDFCROP 1.33, 2012/02/01 - Copyright (c) 2002-2012 by Heiko Oberdiek.
* Restricted mode: disabled
* Option `pdfversion': auto
* OS name: MSWin32
* Arch name: MSWin32-x86-multi-thread
* System: win
* Not found (gswin32c): gswin32c.exe
* Not found (gswin32c): C:\Perl\site\bin\gswin32c.exe
* Not found (gswin32c): C:\Perl\bin\gswin32c.exe
* Not found (gswin32c): C:\GTK\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\OpenVPN\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gs): gs.exe
* Not found (gs): C:\Perl\site\bin\gs.exe
* Not found (gs): C:\Perl\bin\gs.exe
* Not found (gs): C:\GTK\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\OpenVPN\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Search registry at `HKEY_LOCAL_MACHINE/SOFTWARE/'.
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/8.71/
  GS_DLL = C:\Program Files (x86)\gs\gs8.71\bin\gsdll32.dll
  EXE found: C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe
* Found (via registry): C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe
* Autodetected ghostscript command: C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe
* Input file: Instructions-autopp.pdf
* Output file: s.pdf
* Margins: 10 10 10 10
* PDF header: %PDF-1.4
* Using PDF minor version: 4
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: "C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe" -sDEVICE=bbox -    dBATCH -dNOPA
USE -c save pop -f Instructions-autopp.pdf
* Cleanup
* Temporary files: tmp-pdfcrop-1412.tex
!!! Error: Cannot call ghostscript ("C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe")!
* Cleanup
* Temporary files: tmp-pdfcrop-1412.tex

so it seems to find ghostscript but still there is an error. Ghostscript seems to be installed correctly. I can e.g. do the following:

C:\>"C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe" -sDEVICE=bbox -dBATCH -d
NOPAUSE -c save pop -f Instructions-autopp.pdf
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 640 577 978 706
%%HiResBoundingBox: 640.053965 577.439982 977.374658 705.834189

What could I try?

UPDATE

Debug output:

C:\>perl pdfcrop.pl   --margins 10 --debug Instructions-autopp.pdf s.pdf
PDFCROP 1.37, 2012/10/16 - Copyright (c) 2002-2012 by Heiko Oberdiek.
* Restricted mode: disabled
* Option `pdfversion': auto
* Perl executable: C:\Perl64\bin\perl.exe
* Perl version: v5.10.1
* Perl product: ActivePerl, build 1007
* Pointer size: 8
* Pipe support: yes
* Fork support: no
* OS name: MSWin32
* Arch name: MSWin32-x64-multi-thread
* System: win
* Not found (gswin64c): gswin64c.exe
* Not found (gswin64c): C:\Perl64\site\bin\gswin64c.exe
* Not found (gswin64c): C:\Perl64\bin\gswin64c.exe
* Not found (gswin64c): C:\GTK\bin\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\OpenVPN\bin\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\ispell\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\ispell\gswin64c.exe
* Not found (gswin32c): gswin32c.exe
* Not found (gswin32c): C:\Perl64\site\bin\gswin32c.exe
* Not found (gswin32c): C:\Perl64\bin\gswin32c.exe
* Not found (gswin32c): C:\GTK\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\OpenVPN\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gs): gs.exe
* Not found (gs): C:\Perl64\site\bin\gs.exe
* Not found (gs): C:\Perl64\bin\gs.exe
* Not found (gs): C:\GTK\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\OpenVPN\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Search registry at `HKEY_LOCAL_MACHINE/SOFTWARE/'.
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/9.06/
  GS_DLL = C:\Program Files\gs\gs9.06\bin\gsdll64.dll
  EXE found: C:\Program Files\gs\gs9.06\bin\gswin64c.exe
* Found (via registry): C:\Program Files\gs\gs9.06\bin\gswin64c.exe
* Autodetected ghostscript command: C:\Program Files\gs\gs9.06\bin\gswin64c.exe
* Input file: Instructions-autopp.pdf
* Output file: s.pdf
* Margins: 10 10 10 10
* PDF header: %PDF-1.4
* Using PDF minor version: 4
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: "C:\Program Files\gs\gs9.06\bin\gswin64c.exe" -sDEVICE=bbox -dBATCH     -dNOPAUSE -c
 save pop -f Instructions-autopp.pdf
* Cleanup
* Temporary files: tmp-pdfcrop-3284.tex
!!! Error: Cannot call ghostscript `"C:\Program Files\gs\gs9.06\bin\gswin64c.exe"' (Bad
file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable)!
* Cleanup
* Temporary files: tmp-pdfcrop-3284.tex 

Le chemin dÆaccÞs spÚcifiÚ est introuvable)! = The specified path can not be found.

UPDATE The result of your script:

*** system() ***
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 640 577 978 706
%%HiResBoundingBox: 640.053402 577.439982 977.375220 705.851978
* No error.

*** backticks ***
%%BoundingBox: 640 577 978 706
%%HiResBoundingBox: 640.053402 577.439982 977.375220 705.851978
* No error.
==========
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
==========

*** pipe ***
[[GPL Ghostscript 9.06 (2012-08-08)]]
[[Copyright (C) 2012 Artifex Software, Inc.  All rights reserved.]]
[[This software comes with NO WARRANTY: see the file PUBLIC for details.]]
[[Processing pages 1 through 1.]]
[[Page 1]]
%%BoundingBox: 640 577 978 706
%%HiResBoundingBox: 640.053402 577.439982 977.375220 705.851978
* No error.

*** with stderror redirection ***

*** system() ***
Can't spawn "cmd.exe": No such file or directory at test.pl line 26.
! Exit code: 255

*** backticks ***
! Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable
==========
Use of uninitialized value $result in print at test.pl line 33.
==========

*** pipe ***
! Error: Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable

*** with stderror and stdout redirection ***

*** system() ***
Can't spawn "cmd.exe": No such file or directory at test.pl line 26.
! Exit code: 255

*** backticks ***
! Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable
==========
Use of uninitialized value $result in print at test.pl line 33.
==========

*** pipe ***
! Error: Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable

The problem seems to be that cmd.exe can not be found. I put c:\windows\system32 in system variable PATH and now everything works!

(I do not know why c:\windows\system32 was not present any more)

Many thanks for your help!

11
  • What kind of perl are you using? Perhaps your perl does not support pipes. Oct 15, 2012 at 15:09
  • perl -v on the command line gives me: perl 5, version 16. what other information do you need?
    – dziadgba
    Oct 15, 2012 at 15:20
  • Can you try pdfcrop-1.35 with option --debug? I am interested in the line Has pipe:. Also which Perl port you are using (ActiveState, Strawberry Perl, ...)? Oct 15, 2012 at 15:46
  • ActiveState and * Has pipe: yes
    – dziadgba
    Oct 15, 2012 at 16:08
  • In pdfcrop-1.36 I have added more descriptive error messages. What does the error message tells now? Oct 15, 2012 at 16:59

2 Answers 2

5

Perhaps there is a problem with redirection of standard/error output with your Perl version. Try updating. The current version is 5.16.1.1601.

Also I have written a test script that tries different execution methods with and without redirecting:

#!/usr/bin/env perl
use strict;
$^W=1;

use File::Spec::Functions qw(devnull);
my $null = devnull();

my $prg = '"C:\Program Files\gs\gs9.06\bin\gswin64c.exe"';
# $prg = '"C:\Program Files\gs\gs9.05\bin\gswin32c.exe"';

my $testfile = 'Instructions-autopp.pdf';
# $testfile = 'test.pdf';
my $cmdline =
  "$prg -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f $testfile";

sub analyze {
    if ($? == -1) { print "! Execution error: $!/$^E\n"; }
    elsif ($? & 127) { print sprintf "! Signal: %d\n", $? & 127; }
    elsif ($? != 0) { print sprintf "! Exit code: %d\n", $? >> 8; }
    else { print "* No error.\n"; }
}

sub test {
    print "\n*** system() ***\n";

    system($cmdline);
    analyze();

    print "\n*** backticks ***\n";
    my $result = `$cmdline`;
    analyze();
    print "==========\n";
    print $result;
    print "==========\n";

    print "\n*** pipe ***\n";
    my $ret = open(IN, "$cmdline |");
    if ($ret) {
        while (<IN>) {
            chomp;
            print "[[$_]]\n";
        }
        close(IN);
        analyze();
    }
    else {
        print "! Error: Execution error: $!/$^E\n";
    }
}

test();

print "\n*** with stderror redirection ***\n";
$cmdline .= " 2>&1";
test();

print "\n*** with stderror and stdout redirection ***\n";
$cmdline .= " 1>$null";
test();

1;
__END__

The result (example with win32/ActivePerl 16.0.1):

*** system() ***
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
Page 2
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** backticks ***
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.
==========
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Page 2
==========

*** pipe ***
[[GPL Ghostscript 9.05 (2012-02-08)]]
[[Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.]]
[[This software comes with NO WARRANTY: see the file PUBLIC for details.]]
[[Processing pages 1 through 2.]]
[[Page 1]]
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
[[Page 2]]
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** with stderror redirection ***

*** system() ***
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
Page 2
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** backticks ***
* No error.
==========
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
Page 2
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
==========

*** pipe ***
[[GPL Ghostscript 9.05 (2012-02-08)]]
[[Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.]]
[[This software comes with NO WARRANTY: see the file PUBLIC for details.]]
[[Processing pages 1 through 2.]]
[[Page 1]]
[[%%BoundingBox: 72 696 341 767]]
[[%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977]]
[[Page 2]]
[[%%BoundingBox: 72 95 321 770]]
[[%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977]]
* No error.

*** with stderror and stdout redirection ***

*** system() ***
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** backticks ***
* No error.
==========
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
==========

*** pipe ***
[[%%BoundingBox: 72 696 341 767]]
[[%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977]]
[[%%BoundingBox: 72 95 321 770]]
[[%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977]]
* No error.
1

I came to this question because its title matched my problem, though my error messages differed. The previous answer helped; I'm adding this one since it may help future questioners. It also gives me a place to thank @HeikoOberdiek for pdfcrop.

I'm running miktex on windows 7. I also use cygwin, so I have perl on my machine. pdfcrop couldn't find that perl until I added it to my path. pdfcrop still failed, so I checked:

$ perl -version

This is perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-thread-multi-64int
(with 7 registered patches, see perl -V for more detail)

Aha. I need a newer perl than the one that comes with cygwin. So I got one (see below) and tried again. New message: no ghostscript. So I got that too. Now pdfcrop works perfectly.

C:\eb>pdftex -version
MiKTeX-pdfTeX 2.9.4535 (1.40.13) (MiKTeX 2.9)
Copyright (C) 1982 D. E. Knuth, (C) 1996-2012 Han The Thanh
TeX is a trademark of the American Mathematical Society.

C:\eb>perl --version

This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-mul
hread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Binary build 1603 [296746] provided by ActiveState http://www.ActiveState.co
Built Mar 13 2013 13:31:10

C:\eb>pdfcrop -help
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
...
--gscmd <name>      call of ghostscript   (C:\Program Files\gs\gs9.07\bin\gswin64c.exe)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .