代码之家  ›  专栏  ›  技术社区  ›  zjffdu

(EclipseRCP)如何将输出重定向到控制台视图?

  •  2
  • zjffdu  · 技术社区  · 15 年前

    我有两个查看器,一个具有用户输入的文本,另一个查看器是Eclipse内置的控制台视图。我将根据用户的输入运行一个Java程序,并希望在控制台中显示日志信息。有人知道如何将输出重定向到控制台视图吗?

    谢谢

    2 回复  |  直到 8 年前
        1
  •  1
  •   Community CDub    7 年前

    因此,问题 How to write a hyperlink to an eclipse console from a plugin. and writing to the eclipse console. give example of rE到控制台的方向。

    博客帖子 在RCP应用程序中显示控制台

    这些想法仍然是为了创建一个 ouputstream->code>并打开一个新的 console->code>,或者将一个控制台的 messagestream->code>关联到 stdout->code>adn stderr->code>(like my previous answer->a>)

    writing to the eclipse console 举个重定向到控制台的例子。

    博客帖子 Displaying the console in your RCP application

    alt text

    这些想法仍然是为了创造一个 OuputStream 打开一个新的 Console 或将 MessageStream 控制台的 stdout ADN stderr (就像我的 previous answer )

        2
  •  1
  •   Dave Pateral    8 年前

    重定向输出打开 rcp console:。

    import java.io.ioexception;
    导入java.io.outputstream;
    导入java.io.printstream;
    
    导入javax.annotation.postconstruct;
    
    导入org.eclipse.e4.ui.di.focus;
    导入org.eclipse.swt.swt;
    导入org.eclipse.swt.events.disposeevent;
    导入org.eclipse.swt.events.disposelistener;
    导入org.eclipse.swt.widgets.composite;
    导入org.eclipse.swt.widgets.display;
    导入org.eclipse.swt.widgets.text;
    
    公共类控制台视图{
    私人文本文本;
    
    @ PostConstruct
    公共void CreatePartControl(复合父级){
    文本=新文本(父,
    swt.read_swt.multi_swt.v_scroll_swt.h_scroll);
    
    outputstream out=new outputstream()。{
    StringBuffer缓冲区=new StringBuffer();
    
    @重写
    public void write(final int b)引发IOException{
    if(text.isdisposed())
    返回;
    buffer.append((char)b);
    }
    
    @重写
    public void write(byte[]b,int off,int len)引发IOException{
    super.write(b、off、len);
    flush();
    }
    
    @重写
    public void flush()引发IOException{
    final string newtext=buffer.toString();
    display.getdefault().asyncExec(new runnable()){
    public void run()。{
    text.append(newtext);
    }
    (});
    buffer=new StringBuffer();
    }
    };
    
    system.setout(新打印流(out));
    最终的printstream oldout=system.out;
    
    text.addDisposeListener(new DisposeListener()){
    public void widgetDisposed(处置事件e){
    System.Setout(旧版);
    }
    (});
    }
    
    @焦点
    public void setfocus()。{
    text.setfocus();
    }
    }
    < /代码> 
    
    

    屏幕截图:

    截图:

    enter image description here