Get current console output to work with Follow
Hello,
I would like to get the output printed in console tab for the current project, so I can parse it and later do some things with it. Where and how can I find the current console instance and the output that it contains?
Also is there a way to add a listener to the console, so everytime a change is made (new lines in console output) I get notified?
Thanks for the help.
Jan
Please sign in to leave a comment.
Probably this comment would help you: https://intellij-support.jetbrains.com/hc/en-us/community/posts/203361530/comments/203903244
Sure, when you add a ProcessListener to the ProcessHandler you can listen to termination event.
Thanks very much for your answers, but the one about 1st start of console is still something I have issues with.
I am using the ExecutionManager.EXECUTION_TOPIC and the
public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) method, where I add new ProcessListener. This listener though seems to work only from the 2nd+ run of programs which output on console. I debugged it and the handler adds Process Listener, but nothing happens the 1st time. Only the 2nd+ run the added ProcessAdapter works.
Is there a way to register this listener when the Process is starting or what is the issue, as I dont understand, why the listener seems to work only after 2nd time.
Thanks in advance.
Thank you, it helped a lot.
But I have another question - is there a way to say when the process which is outputing on the console finished? Other than reading and parsing the text of the output?
Thanks in advance.
And one more question, which I thought of when working with the solution written in that comment, this seems to work only when I am using the console for the 2nd and more times. For the 1st time, nothing happens, as processStarted method does not work for this apparently.
Which method should I override and implement so that I can use the text from the console from the 1st time something is executed and outputs on console?
Thanks in advance
You can subscribe to ExecutionManager.EXECUTION_TOPIC in advance, when IDE just has started. So you'll be able to get every output line you need.