[英]How can I run a ruby file in command line from Java?
I want to run a Ruby file in a given path, from Java. 我想从Java在给定的路径中运行Ruby文件。
For instance: C:\\Documents and Settings\\Administrator\\Desktop\\myruby.rb 例如: C:\\ Documents and Settings \\ Administrator \\ Desktop \\ myruby.rb
In the command line i need to run the ruby file ruby myruby.rb
在命令行中,我需要运行ruby文件
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: 我的myruby.rb文件包含以下代码:
puts "Hello"
The above builds sucessfully. 以上成功构建。 But "Hello" is not printed.
但是不会打印“ Hello” 。
Thank you for your help. 谢谢您的帮助。
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\""};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.