user081608
user081608

Reputation: 1113

Running Ruby script from Java

I am trying to run a Ruby script from Java by doing the following:

public static void main(String[] args) {
    try {
        Process process = Runtime.getRuntime().exec("ruby /path/to/file/file.rb");
        process.waitFor();
        System.out.println(process.exitValue()); 
    } 
    catch (Exception e) {
        e.printStackTrace();
    }
}

When I this is run, I get 1 as the exit value. In my Ruby script, I am using Watir and Nokogiri thus a browser should be used. Nothing happens.

If I copy ruby /path/to/file/file.rb into my terminal, it runs correctly. Any reason why this isn't working correctly?

Upvotes: 0

Views: 843

Answers (1)

vstrom coder
vstrom coder

Reputation: 295

You need to consume the standard output and standard error streams to get output from your process and find out what is wrong. See the answer to "Using a thread to capture process output".

Upvotes: 3

Related Questions