我正在使用PDFSam的控制台来拆分和合并一些PDF文件。我可以使用.bat文件半自动地完成这项工作,但我想用R完成整个过程。
我的.bat文件中的以下代码可以工作:
C:
cd "/Program Files/pdfsam/bin/"
run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split但是,我的R shell命令中的这个“等效”代码没有返回错误,但似乎不起作用。
shell('C:
cd "/Program Files/pdfsam/bin/"
run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')我的shell命令中有没有遗漏的选项?我已经尝试了?shell中列出的几个选项,但都没有用。
我使用的是windows XP和R版本2.13.1 (2011-07-08)平台: i386-pc-mingw32/i386 (32位)
谢谢,汤姆
发布于 2011-09-13 16:11:50
您可以通过&将多个命令连接在一起,从而将多个命令传递给shell,因此下面的命令应该可以工作:
shell('C: & cd C:/Program Files/pdfsam/bin & run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')但作为一种解决办法,您可以临时更改R工作目录:
current.wd <- getwd()
setwd("C:/Program Files/pdfsam/bin")
shell('run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')
setwd(current.wd)如果你经常这样做,那就写一个函数:
shell.in.dir <- function(dir, ...) {
current.wd <- getwd()
on.exit(setwd(current.wd))
setwd(dir)
shell(...)
}
shell.in.dir("C:/Program Files/pdfsam/bin",
'run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')发布于 2011-09-13 04:34:16
这并不能完全回答您的问题,但您可以尝试使用system("youBatFile.bat")作为替代方案。
https://stackoverflow.com/questions/7393579
复制相似问题