Pregunta

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.

¿Fue útil?

Solución

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\""};
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top