简体   繁体   English

如何捕获从Ruby调用的shell脚本的输出?

[英]How can I capture the output of a shell script invoked from Ruby?

I am catching emails to "script@localhost" with /etc/aliases: 我正在使用/ etc / aliases捕获到“ script @ localhost”的电子邮件:

script:   root,"|/path-to-my-script"

this gets an email on STDIN and I am parsing and passing it to other scripts. 这会收到有关STDIN的电子邮件,我正在解析并将其传递给其他脚本。

#!/usr/bin/ruby
email = ARGF.read
...parse...parse-some-more...
system("/my-other-script.sh #{email.todo}")

What would be a best way to capture the STDOUT of my-other-script.sh for troubleshooting? 捕获my-other-script.sh的STDOUT进行故障排除的最佳方法是什么?

Did you take a look at IO.popen yet? 您看过IO.popen吗?

I'm not an expert, but it might be worth taking a look there. 我不是专家,但是值得一看。

I am going with : 我要和:

out = `/my-other-script.sh #{email.todo} 2>&1`
log.debug $?.exitstatus
log.debug out

seems to work 似乎有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM