如何使用Ruby获取Java输出 [英] How to get java output with ruby
问题描述
我目前正在编写一个需要Java jar输出的ruby应用程序.
I am currently writing a ruby application that requires the output of a java jar.
我目前无法使用open3从java命令获得任何输出.
I currently can not get any output from the java command using open3.
但是,我已经使用'ls'成功测试了以下红宝石代码.
I have however, successfully tested the following ruby code using 'ls'.
require 'open3'
Open3.popen3('java -version') do |stdrin, stdout, stderr|
@output = stdout.read
end
我也尝试过使用Java的绝对路径:'/opt/java/jre/bin/java',但没有成功.
I have also tried using an absolute path for java: '/opt/java/jre/bin/java' with no success.
先谢谢您
推荐答案
java -version
写入STDERR,因此以下内容应起作用:
java -version
writes to STDERR, so the following should work:
@output = stderr.read
在Linux上,可以通过抑制STDERR或STDOUT来检查输出的外壳程序:
On Linux, you can check in the shell where the output is going by supressing either STDERR or STDOUT:
java -version >/dev/null
仍然打印信息.
这篇关于如何使用Ruby获取Java输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!