Question

I want to run a Ruby file in a given path, from Java.

For instance: C:\Documents and Settings\Administrator\Desktop\myruby.rb

In the command line i need to run the ruby file ruby myruby.rb

I have tried the following code but it's not working:

final String[] command = new String[]{"cmd", "/c", "C:\\Documents and Settings\\Administrator\\Desktop\\ruby myruby.rb"};

final Process process = Runtime.getRuntime().exec(command);

My myruby.rb file contains the following code:

puts "Hello"

The above builds sucessfully. But "Hello" is not printed.

Thank you for your help.

Was it helpful?

Solution

Have you tried putting the file name in quotes?

final String[] command = new String[]{"cmd", "/c",
       "\"C:\\Documents and Settings\\Administrator\\Desktop\\ruby muruby.rb\""};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top