我尝试使用convert命令将大量pdf文件转换为图像。我从我的文件夹中读取所有文件,这些文件有pdf和html文件,但是html文件的扩展名是“.pdf”我从远程服务器接收到这些文件,因此无法检查哪些文件是pdf文件,哪些不是我用了这个代码:

%x[convert "#{source_path}" "#{destination_path}".jpg]

source_path指向html文件时,将返回以下错误:
GPL Ghostscript 8.60:不可恢复
错误,退出代码1转换:PASScript
委派失败/home/20100.pdf': @ error/pdf.c/ReadPDFImage/645. convert: missing an image filename /home/test/20100-1.jpg'@
错误/convert.c/ConvertImageCommand/2970。
成功错误:文件中有语法错误-
操作数堆栈:
执行堆栈:%IpPx退出
.runexec2—nostringval--
--nostringval--nostringval--2%停止_push--nostringval--
--nostringval--nostringval--false 1%已停止按1889 1
3%乳白色流行1888 1 3
%1872年1月3日
%猫眼石1755 1 3
%浑浊的波普——怀斯林瓦尔--
%errorexec_pop.runexec2
--nostringval--nostringval--nostringval--2%已停止推送字典堆栈:
--dict:1149/1684(ro)(g)---dict:0/20(g)---dict:70/200(l)--当前分配模式为本地
当前文件位置为1
是否可以获取任何布尔值,或者是否有任何方法来标识shell脚本是否正确执行?

最佳答案

是,检查$?.exitstatus是否为0。

>> %x{ls /etc/services}
=> "/etc/services\n"
>> $?.exitstatus
=> 0

>> %x{ls failfail}
ls: cannot access failfail: No such file or directory
=> ""
>> $?.exitstatus
=> 2

关于ruby - 通过ruby捕获shell脚本执行日志,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6014580/

10-12 12:20