Attach process to Debug Console

Hello everyone,

I am trying to send some commands through debug console but I can't get reference to it.
Currently I am using this code, but its not work because component is wrong.

ToolWindowManager manager = ToolWindowManager.getInstance(project);
window
= manager.getToolWindow("Debug");


window
.show(null);
window
.activate(new Runnable() {
    @Override
    public void run
() {

        ContentManager contentManager = window.getContentManager();
        
Content[] contents = contentManager.getContents();
        for
(Content content:contents) {
            Component component = content.getComponent();
            if
(component instanceof ConsoleView) {
                ((ConsoleView) component).attachToProcess(handler);
            
}

        }
    }
});


Possibly there are another way to get it?

7 comments
Comment actions Permalink

Normally a debug console already has a process attached. What exactly are you trying to accomplish?

0
Comment actions Permalink

I need to send some commands through this console.

0
Comment actions Permalink

There can be multiple processes running in the debugger at the same time. XDebuggerManager.getInstance(project).getSessions() returns you the list of active debug sessions. For a session, you can call getRunContentDescriptor().getExecutionConsole() to get the console. Normally the returned object will be an instance of ConsoleView.

0
Comment actions Permalink

Thank you for your help.

But is launched JavaCommandLine and debug has different handlers? Because my command line that should read commands didn't see commands that I sent programmatically.

0
Comment actions Permalink

How exactly are you sending your commands?

0
Comment actions Permalink
RemoteConnection connection = new RemoteConnection(true, parameters.getDebug_host(), parameters.getDebug_port(), false);

RunContentDescriptor descriptor = attachVirtualMachine(state, environment, connection, false);
ExecutionResult executionResult;
project
= environment.getProject();
executionResult = state.execute(environment.getExecutor(), this);

handler
= executionResult.getProcessHandler();
initConsole();
handler
.startNotify();
stream
= handler.getProcessInput();
 
stream.write(cmd.getBytes());
stream
.flush();
0
Comment actions Permalink

Thanks for the help i fix my problem

 
handler = descriptor.getProcessHandler();
handler
.startNotify();
stream
= handler.getProcessInput();
0

Please sign in to leave a comment.