简体   繁体   中英

invoke shell command from within Aptana/ Eclipse

I'm trying to add a feature to Aptana, and this feature requires that I find out where the gems are on the system. In ruby I would run a command like...

gem_folder_path = `rvm gemdir`

In java obviously there are more factors to deal with, but it seems that the java solution I've been trying to implement won't work within the bounds of the eclipse/ Aptana IDE (I've tested it standalone and it works fine in my helloworld.java file). Are shell commands disabled or something?

Here's my current java solution which is not functional.

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 "";
    }
}

this tutorial will show u how to run native OS commands. Works for me from Eclipse/Tomcat and just Java http://www.java-programming.info/tutorial/pdf/java/22-Native-Apps.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM