IntelliJ Plugins: Getting the output of an OS command Follow
Answered
I am trying to build an IntelliJ plugin to execute an OS command, parse the output and then create a menu of the parsed output.
However I'm stuck on how I can grab the output from the OSProcessHandler
and parse it as a String before showing it as part of the view.
public class MyClass extends AnAction {
private static ConsoleView view = null;
private static ToolWindow window = null;
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (project == null)
return;
GeneralCommandLine generalCommandLine = new GeneralCommandLine(getAccounts());
generalCommandLine.setCharset(Charset.forName("UTF-8"));
//generalCommandLine.setWorkDirectory(project.getBasePath());
ProcessHandler processHandler = null;
try {
processHandler = new OSProcessHandler(generalCommandLine);
} catch (ExecutionException ex) {
throw new RuntimeException(ex);
}
if (view == null) {
TextConsoleBuilderFactory factory = TextConsoleBuilderFactory.getInstance();
TextConsoleBuilder builder = factory.createBuilder(project);
view = builder.getConsole();
}
view.attachToProcess(processHandler);
processHandler.startNotify();
if (window == null) {
ToolWindowManager manager = ToolWindowManager.getInstance(project);
window = manager.registerToolWindow("Cat console", true, ToolWindowAnchor.BOTTOM);
final ContentManager contentManager = window.getContentManager();
Content content = contentManager
.getFactory()
.createContent(view.getComponent(), "", false);
contentManager.addContent(content);
window.show(() -> {});
}}
private ArrayList<String> getAccounts(){
ArrayList<String> cmds = new ArrayList<>();
cmds.add("/usr/local/bin/getaccountscmd");
cmds.add("ls");
System.out.println(cmds.toString());
return cmds;
}
Please sign in to leave a comment.
com.intellij.execution.process.ScriptRunnerUtil