Tuesday, 15 March 2011

windows - Different results when R script is automated -



windows - Different results when R script is automated -

the next command executes ghostscript on pdf file. (the pdf_file variable contains path pdf)

bbox <- system(paste( "c:/gs/gs8.64/bin/gswin32c.exe -sdevice=bbox -dnopause -dbatch -f", pdf_file, "2>&1" ), intern=true)

after execution bbox includes next character string.

gpl ghostscript 8.64 (2009-02-03) copyright (c) 2009 artifex software, inc. rights reserved. software comes no warranty: see file public 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 local lastly os error: no such file or directory gpl ghostscript 8.64: unrecoverable error, exit code 1

this string manipulated in order boundingbox dimensions (36 2544 248 2825) isolated , used cropping pdf file. far works ok.

however, when schedule script in task manager (using rscript.exe or rcmd.exe batch), or when script within r chunk , press knit html, bbox gets next character string lacks boundingbox information, , makes unusable:

gpl ghostscript 8.64 (2009-02-03) copyright (c) 2009 artifex software, inc. rights reserved. software comes no warranty: see file public details. processing pages 1 through 1. page 1 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 local lastly os error: no such file or directory

how can on problem , have script run automated?

(the script comes accepted reply that question)

the 2>&1 add together @ end of command sent ghostscript interpreter, not shell. ghostscript interprets file, hence error. used procmon @ process creation:

to create shell interpret it, must prefix command cmd /c, this

> bbox <- system(paste("cmd /c c:/progra~1/gs/gs9.07/bin/gswin64c.exe -sdevice=bbox -dnopause -dbatch -q -f",pdf_file,"2>&1"), intern=true) > print (bbox) [1] "%%boundingbox: 28 37 584 691" "%%hiresboundingbox: 28.997999 37.511999 583.991982 690.839979"

windows r redirect automation ghostscript

No comments:

Post a Comment