Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6716525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:44:38+00:00 2026-05-26T08:44:38+00:00

I’m writing an Eclipse plug-in in which the user can interact with another process

  • 0

I’m writing an Eclipse plug-in in which the user can interact with another process via the Console view (in this case, an interpreter), for example, evaluate expressions and so on.

Sometimes the program needs to ask the interpreter for certain values. These interactions however, shouldn’t be shown in the console view to the user.

I have following instances:

private IProcess process;
private ILaunch launch;
private IStreamsProxy proxy;

the queries my program do are made via adding an IStreamListener to the proxy:

proxy.getOutputStreamMonitor().addListener(new IStreamListener(){
    @Override
    public void streamAppended(String response, IStreamMonitor arg1) {
             doSomeStuffWiththeRepsonse(response);
        }
    });

while the listener is listening to the OutputStreamMonitor of the proxy, I don’t want the response to pop up in the console view of the plugin.

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:44:39+00:00Added an answer on May 26, 2026 at 8:44 am

    Okay, here is how I did it.

    The launch system of Eclipse works as follows:

    1. Implement a ILaunchConfigurationDelegate, the only method in this interface is launch, which recieves an ILaunchConfiguration, a mode, an ILaunch and an IProgressMonitor.

    In my program, launch starts an inferiorProcess using DebugPlugin.exec() using a commandline argument. Then a new Process is created by calling DebugPlugin.newProcess() with the ILaunch, the inferiorProcess, the name for the interpreter and some attributes.
    This method creates a new RuntimeProcess and adds it to the ILaunch and vice versa.

    2. Define a LaunchConfigurationType by using the extension point org.eclipse.debug.core.launchConfigurationTypes and add it to the plugin.xml:

    <extension
        point="org.eclipse.debug.core.launchConfigurationTypes">
        <launchConfigurationType
                delegate="myplugin.MyLaunchConfigurationDelegate" (1)
                id="myplugin.myExternalProgram" (2)
                modes="run" (3)
                name="MyExternalProgram" (4)
                public="false"> (5)
          </launchConfigurationType>
    </extension>
    

    The extension point gives the exact path to the ILaunchConfigurationDelegate class created as above (1) and an unqiue identifier (2) to retrieve the instance of ILaunchConfigurationType from the LaunchManager used to launch the program. (3) defines the modes it can run as, run and debug. The name (4) is later shown in the top bar of the console view. If you only want to access and launch your external program programmatically in your plug-in (and not via the Run drop-down menu) (5) must be set to false.

    3. Create a class that stores the Instances of IProcess, ILaunch and IStreamsProxy and which calls apropiate methods to start the process and to write onto the streamsproxy. A method for starting the process could look like this:

    // is the process already running?
    public boolean isRunning() {
            boolean result = false;
            try {
                if (this.process != null) {
                    result = true;
                    this.process.getExitValue();
                    result = false;
                }
            }
            catch (DebugException exception) {
            }
            return result;
    }
    
    // start the process
    public void start() {
            try {
                if (!isRunning()) {
                    // get the ILaunchConfigurationType from the platform
                    ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(myplugin.myExternalProgram);
                    // the ILaunchConfigurationType can't be changed or worked with, so get a WorkingCopy
                    ILaunchConfigurationWorkingCopy copy = configType.newInstance(null, "myExternalProgram");
                    this.launch = copy.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
                    IProcess[] processes = this.launch.getProcesses();
    
                    if (processes.length > 0) {
                        // get the IProcess instance from the launch
                        this.process = this.launch.getProcesses()[0];
                        // get the streamsproxy from the process
                        this.proxy = this.process.getStreamsProxy();                       
                    }
                }
            }
            catch (CoreException exception) {
            }
            if (isRunning())
                // bring up the console and show it in the workbench
                showConsole();
        }
    
    public void showConsole() {
            if (this.process != null && this.process.getLaunch() != null) {
                IConsole console = DebugUITools.getConsole(this.process);                
                ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = page.findView("org.eclipse.ui.console.ConsoleView");
                if (view != null) 
                    view.setFocus();
              }
        }
    

    Now to the initial problem of the question
    The IStreamsListener of the console view, which listens to the OutputStreamMonitor of the IStreamsProxy could not be retrieved and thus not being stopped of listening. Prints to the console could not be prevented. OutputStreamMonitor doesn’t provide methods to get the current listeners. It is not possible to just subclass it and override/add some methods, because the important fields and methods are private.

    http://www.java2s.com/Open-Source/Java-Document/IDE-Eclipse/debug/org/eclipse/debug/internal/core/OutputStreamMonitor.java.htm

    Just copy the code and add a get-method for the fListeners field and change some method modifiers to public.
    In order to get your own OutputStreamMonitor into the system, you need to create your own IStreamsProxy. Again only subclassing wont work, you need to copy the code again and make some changes.

    http://www.java2s.com/Open-Source/Java-Document/IDE-Eclipse/debug/org/eclipse/debug/internal/core/StreamsProxy.java.htm

    Important:

    public class MyStreamsProxy implements  IStreamsProxy, IStreamsProxy2 {
        /**
         * The monitor for the output stream (connected to standard out of the process)
         */
        private MyOutputStreamMonitor fOutputMonitor;
        /**
         * The monitor for the error stream (connected to standard error of the process)
         */
        private MyOutputStreamMonitor fErrorMonitor;
    
    (...)
    
    public MyStreamsProxy(Process process) {
            if (process == null) {
                return;
            }
            fOutputMonitor = new MyOutputStreamMonitor(process
                    .getInputStream());
            fErrorMonitor = new MyOutputStreamMonitor(process
                    .getErrorStream());
            fInputMonitor = new InputStreamMonitor(process
                    .getOutputStream());
            fOutputMonitor.startMonitoring();
            fErrorMonitor.startMonitoring();
            fInputMonitor.startMonitoring();
        }
    

    The only thing remaining is providing your own IProcess that uses your IStreamsProxy. This time subclassing RuntimeProcess and overriding the method createStreamsProxy() is enough:

    public class MyProcess extends RuntimeProcess {
    
        public MyProcess(ILaunch launch, Process process, String name,
                Map attributes) {
            super(launch, process, name, attributes);
        }
    
        @Override
        protected IStreamsProxy createStreamsProxy() {
            String encoding = getLaunch().getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING);
            return new MyStreamsProxy(getSystemProcess());
        }
    }
    

    MyProcess is integrated by creating a new instance of it in the launch method in the ILaunchConfigurationDelegate instead of using DebugPlugin.newProcess().

    Now it is possible to hide and expose the output of the console view.

        /**
         * Storage field for the console listener
         */
        private IStreamListener oldListener;
    
    
        /**
         * Hides the output coming from the process so the user doesn't see it.
         */
        protected void hideConsoleOutput() {
            MyOutputStreamMonitor out 
                = (MyOutputStreamMonitor) this.process.getStreamsProxy().getOutputStreamMonitor();
            List<IStreamListener> listeners = out.getListeners();
            // the console listener
            this.oldListener = listeners.get(0);
            out.removeListener(this.oldListener);
    
        }
    
        /**
         * Reverts the changes made by hideConsoleOutput() so the user sees the response from the process again.
         */
        protected void exposeConsoleOutput() {
            MyOutputStreamMonitor out 
            = (MyOutputStreamMonitor) this.process.getStreamsProxy().getOutputStreamMonitor();
            out.addListener(oldListener);
            this.oldListener = null;
    
        }
    

    The hide and expose methods have to be called before any other listeners are added. There might be a better solution, however, this works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.