次のコマンドは、pdfファイルでghostscriptを実行します。 (pdf_file
変数はそのPDFファイルへのパスを含む)Rスクリプトが自動化された場合の結果が異なります
bbox <- system(paste("C:/gs/gs8.64/bin/gswin32c.exe -sDEVICE=bbox -dNOPAUSE -dBATCH -f", pdf_file, "2>&1"), intern=TRUE)
実行bbox
は、以下の文字列を含む後。
GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 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: 36 2544 248 2825
%%HiResBoundingBox: 36.395015 2544.659922 247.070032 2824.685914
Error: /undefinedfilename in (2>&1)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1147/1684(ro)(G)-- --dict:1/20(G)-- --dict:69/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.64: Unrecoverable error, exit code 1
この文字列は、次に、PDFファイルをトリミングするために単離して使用されるこのBoundingBox寸法(36 2544 248 2825)ために操作されます。これまでのところすべて正常に動作します。
しかし、タスクマネージャ(Rscript.exeまたはRcmd.exe BATCHを使用)でこのスクリプトをスケジュールするとき、またはスクリプトがRチャンク内にあり、knit HTML
を押すと、bboxはBoundingBoxがない次の文字列を取得しますこの問題を乗り越えてスクリプトを自動実行するにはどうすればよいですか?
(スクリプトがthat questionに受け入れ答えから来ている)
のようなバウンディングボックスがに書き込まれますstderr、 、 '2>&1'はstderrをstdoutにリダイレクトします。 しかし、この構文は明らかにWindowsでは認識されません。 –
Windowsのコマンドプロセッサで認識されますが、これはコマンドシェルから実行されていないため、リダイレクトは実行されません。 – KenS
'pdf_file'にはPDFの完全パスが含まれていますか? – robertklep