gpt4 book ai didi

ruby - 通过 ruby​​ 捕获 shell 脚本执行日志

转载 作者:太空宇宙 更新时间:2023-11-03 17:18:20 24 4
gpt4 key购买 nike

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

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

source_path指向一个html文件时,返回如下错误:

GPL Ghostscript 8.60: Unrecoverable error, exit code 1 convert: Postscript delegate failed /home/20100.pdf': @
error/pdf.c/ReadPDFImage/645. convert:
missing an image filename
/home/test/20100-1.jpg' @ error/convert.c/ConvertImageCommand/2970. Success Error: /syntaxerror in -file- Operand stack:

Execution stack: %interp_exit
.runexec2 --nostringval--
--nostringval-- --nostringval-- 2 %stopped_push --nostringval--
--nostringval-- --nostringval-- false 1 %stopped_push 1889 1
3 %oparray_pop 1888 1 3
%oparray_pop 1872 1 3
%oparray_pop 1755 1 3
%oparray_pop --nostringval--
%errorexec_pop .runexec2
--nostringval-- --nostringval-- --nostringval-- 2 %stopped_push Dictionary stack:
--dict:1149/1684(ro)(G)-- --dict:0/20(G)-- --dict:70/200(L)-- Current allocation mode is local Current file position is 1

是否可以获取任何 bool 值,或者有什么方法可以识别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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com