2

I am currently writing a ruby application that requires the output of a java jar.

I currently can not get any output from the java command using open3.

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

I have also tried using an absolute path for java: '/opt/java/jre/bin/java' with no success.

Thank you, in advance

3
  • Maybe there is output waiting to be read from stderr Commented Apr 27, 2012 at 16:41
  • As Niklas B. has answered, java -version writes to STDERR. If this doesn't explain the problem you're having then please update the question to show something closer to what the jar you're trying to execute does. Commented Apr 27, 2012 at 16:44
  • Yep... i'm guessing the command with the jar file outputted an error (either it didn't find the jar file, or some other thing went wrong, possibly something missing in CLASSPATH). Can't tell for sure without more info. Commented Apr 27, 2012 at 16:48

2 Answers 2

4

java -version writes to STDERR, so the following should work:

@output = stderr.read

On Linux, you can check in the shell where the output is going by supressing either STDERR or STDOUT:

java -version >/dev/null

still prints the information.

Sign up to request clarification or add additional context in comments.

1 Comment

I worked, Thank you so much =) I been banging my head against this for an hour lol
0

Do you need open3, specifically? In Ruby 1.9, i would do:

pipe = IO.popen( [ '/path/to/java', '-jar', '/path/to/jarfile.jar',
                 {SDTERR=>STDOUT} ]
pipe.close_write
puts pipe.readlines

But there is often a lot more to this to running a Java program (setting up the CLASSPATH, for example); so you may be better off running a shell script that runs the Java program.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.