Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.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 从Aptana/Eclipse中调用shell命令_Java_Eclipse_Aptana - Fatal编程技术网

Java 从Aptana/Eclipse中调用shell命令

Java 从Aptana/Eclipse中调用shell命令,java,eclipse,aptana,Java,Eclipse,Aptana,我正在尝试向Aptana添加一个功能,这个功能要求我找出系统中的gems在哪里。在ruby中,我会运行如下命令 gem_folder_path = `rvm gemdir` 在java中,显然有更多的因素需要处理,但我尝试实现的java解决方案似乎无法在eclipse/Aptana IDE的范围内工作(我已经单独测试了它,并且在我的helloworld.java文件中工作良好)。shell命令被禁用了吗 这是我目前的java解决方案,它不起作用 public static String get

我正在尝试向Aptana添加一个功能,这个功能要求我找出系统中的gems在哪里。在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 "";
    }
}

本教程将向您展示如何运行本机OS命令。在Eclipse/Tomcat和Java中为我工作

谢谢你的图坦卡蒙,但图坦卡蒙包含了我在谷歌上找到的解决方案。这个问题似乎是针对大型java应用程序或eclipse插件的。