【问题标题】:invoke shell command from within Aptana/ Eclipse从 Aptana/Eclipse 中调用 shell 命令
【发布时间】:2013-04-06 19:13:15
【问题描述】:

我正在尝试向 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 "";
    }
}

【问题讨论】:

    标签: java eclipse aptana


    【解决方案1】:

    本教程将向您展示如何运行本机操作系统命令。适用于 Eclipse/Tomcat 和 Java http://www.java-programming.info/tutorial/pdf/java/22-Native-Apps.pdf

    【讨论】:

    • 感谢您的 tut,但该 tut 包含我在 google 上找到的解决方案。该问题似乎特定于大型 Java 应用程序或特定于 Eclipse 插件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多