Read text from “Run” window

Answered

I'm trying to read the text from the "Run" window or get the error text. As far as I'v done, I'm able to read the text from the editor and NOT the "Run" window. Any idea on how this can be done ?

12 comments
Comment actions Permalink

You can add a listener to running ProcessHandler and get notifications about error/out/system messages, it's ProcessListener.onTextAvailable(ProcessEvent event, Key outputType). ProcessHandler instance could be found via ExecutionManager.getInstance(project).getContentManager()

0
Comment actions Permalink

Please write a sample code for this.

0
Comment actions Permalink

final Project project = ...


    RunContentDescriptor selectedContent = ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
    if (selectedContent == null) return;
    ProcessHandler processHandler = selectedContent.getProcessHandler();
    if (processHandler == null || processHandler.isProcessTerminated()) return;
    processHandler.addProcessListener(new ProcessAdapter() {
      @Override
      public void onTextAvailable(ProcessEvent event, Key outputType) {
        ProcessHandler processHandler = event.getProcessHandler();
        if (outputType != ProcessOutputTypes.STDERR) return;
        String text = event.getText();
        if (text != null && text.toLowerCase().contains("error")) {
          new Notification("error-message", processHandler.toString(), text, NotificationType.ERROR).notify(project);
        }
      }
    });

 

1
Comment actions Permalink

Each time the user run a project I want to get all runtime and compile time errors. I have actions and project components in my plugin but I don't know where I should put your piece of code.

As I understand this code add a listener for the event of running the project so this code should be run one time in project initialization so I put this in poject component plugin but it doesn't work.

I really appreciate any help you can provide.

0
Comment actions Permalink

The example above was about listening to output console when you start certain RunConfiguration.

To get compile time errors and warnings you should use CompilerManager, CompilationStatusListener and CompileContext.

1
Comment actions Permalink

What about exceptions? I also need the line of code which exceptions happen.

0
Comment actions Permalink

I think it should be parsed from output text too.

0
Comment actions Permalink

What is the name of classes and methods for finding output text including exceptions?

0
Comment actions Permalink

As I understand you should parse exceptions from text by yourself.

0
Comment actions Permalink

I understood what you are saying. My question is how should I find that text.

I have tried to use your sample code but as I mentioned before my code in onTextAvailable method never run.

I put your sample code in projectOpened() method of my plugin project component to find that text but it doesn't work!

I will be grateful if you can send me this information because I really need this by end of this week.

Thank you.

 

0
Comment actions Permalink

In projectOpened() you should use code like this:

project.getMessageBus().connect(/some disposable/).subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {
        @Override
        public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) {
          //here you can add listener to existing 'live' output console

handler.addProcessListener(new ProcessAdapter() {
      @Override
      public void onTextAvailable(ProcessEvent event, Key outputType) {
        ProcessHandler processHandler = event.getProcessHandler();
        if (outputType != ProcessOutputTypes.STDERR) return;
        String text = event.getText();
        if (text != null && text.toLowerCase().contains("error")) {
          new Notification("error-message", processHandler.toString(), text, NotificationType.ERROR).notify(project);
        }
      }
    });
        }
      });

0
Comment actions Permalink

I've written  such code in  actionPerformed method of a class which extends AnAction  , when i run the code ,the selectedContent   always returns null, I don't know why.  look forward your reply

Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ProgramRunnerUtil.executeConfiguration(project, runnerAndConfigurationSettings, executor);
RunContentDescriptor selectedContent = ExecutionManager.getInstance(project).getContentManager().getSelectedContent();

 

0

Please sign in to leave a comment.