我正在尝试向 Aptana 添加一项功能,而此功能要求我找出系统上的 gem 所在的位置。在 ruby 中,我会运行类似的命令...
gem_folder_path = `rvm gemdir`
在 java 中显然有更多的因素需要处理,但似乎我一直在尝试实现的 java 解决方案在 eclipse/Aptana IDE 的范围内不起作用(我已经独立测试过它并且它在我的 helloworld.java 文件)。shell命令是否被禁用或什么?
这是我当前不起作用的 java 解决方案。
public static String getGemsDirectory()
{
    try
    {
        Process proc = Runtime.getRuntime().exec("which ruby");
        BufferedReader stdInput = new BufferedReader(new 
                                        InputStreamReader(proc.getInputStream()));
        BufferedReader stdError = new BufferedReader(new 
                                        InputStreamReader(proc.getErrorStream()));
        String s;
        String commandOutput = "";
        // read the output from the command
        System.out.println("Here is the standard output of the command:\n");
        while ((s = stdInput.readLine()) != null) {
            //System.out.println(s);
            commandOutput += s;
        }
        // read any errors from the attempted command
        System.out.println("Here is the standard error of the command (if any):\n");
        while ((String s = stdError.readLine()) != null) {
            //System.out.println(s);
            commandOutput += s;
        }
        int statusCode = proc.exitValue();
        return commandOutput;
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace(); 
        return "";
    }
}