I'm looking to run command programatically Follow
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?
Please sign in to leave a comment.
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.
Sweet I'll try that.
Dmitry,
Do you have an example of this usage it's not presenting itself in my googles!
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.
i have same question how to use OSProcessHandler ConsoleView