Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Java在命令行中运行ruby文件?_Java_Command Line_Command Prompt_Runtime.exec - Fatal编程技术网

如何从Java在命令行中运行ruby文件?

如何从Java在命令行中运行ruby文件?,java,command-line,command-prompt,runtime.exec,Java,Command Line,Command Prompt,Runtime.exec,我想从Java在给定路径中运行Ruby文件 例如:C:\Documents and Settings\Administrator\Desktop\myruby.rb 在命令行中,我需要运行ruby文件ruby myruby.rb 我尝试了以下代码,但不起作用: final String[] command = new String[]{"cmd", "/c", "C:\\Documents and Settings\\Administrator\\Desktop\\ruby myruby.rb"

我想从Java在给定路径中运行Ruby文件

例如:C:\Documents and Settings\Administrator\Desktop\myruby.rb

在命令行中,我需要运行ruby文件
ruby myruby.rb

我尝试了以下代码,但不起作用:

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

final Process process = Runtime.getRuntime().exec(command);
Mymyruby.rb文件包含以下代码:

puts "Hello"
上述构建成功。但是,“Hello”没有打印出来


谢谢你的帮助

您是否尝试过将文件名用引号括起来

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

是的,我跑得很成功。但是我在myruby.rb中放了“Hello”。这不是印刷品。