I'm looking to run command programatically

I'd like to have my plugin use the CLI to perform various build and scaffolding tasks.

I'd like the end user to see the command and it's ouptut.

What's the best way to achieve this?

My first stab was to use this:
public static String execCmd(String cmd) throws java.io.IOException {
        Process proc = Runtime.getRuntime().exec(cmd);
        java.io.InputStream is = proc.getInputStream();
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        String val = "";
        if (s.hasNext()) {
            val = s.next();
        }
        else {
            val = "";
        }
        return val;
    }

This works as designed.  How should I take that output and display it to the user?

Should I be using exec or some other built in mechanism?

4 comments
Comment actions Permalink

You can use the OSProcessHandler class to run a process and capture its output, and the ConsoleView interface to display the output to the user.

0
Comment actions Permalink

Sweet I'll try that.

0
Comment actions Permalink

Dmitry,
Do you have an example of this usage it's not presenting itself in my googles!

0
Comment actions Permalink

Have you tried checking out the source code of IntelliJ IDEA Community Edition and using Find Usages? Both of those APIs have plenty of usages in the codebase.

0

Please sign in to leave a comment.