【问题标题】:ant task "sshexec", how to print the remote message in the console?蚂蚁任务“sshexec”,如何在控制台打印远程消息?
【发布时间】:2012-10-12 10:27:10
【问题描述】:

我在eclipse中开发了一个插件,这个插件应该调用ant tasksshexec。问题是如何在 Eclipse 控制台中打印远程消息?

我的代码如下:

 Project p = new Project(); 

 MessageConsole console = new MessageConsole("building", null); 
 IConsoleManager manager = (IConsoleManager) ConsolePlugin.getDefault().getConsoleManager(); 
 manager.addConsoles(new IConsole[] { console }); 
 manager.showConsoleView(console); 

 MessageConsoleStream cs = console.newMessageStream(); 
 cs.setColor(Display.getDefault().getSystemColor(SWT.COLOR_BLUE)); 
 PrintStream ps = new PrintStream(cs); 

 final DefaultLogger consoleLogger = new DefaultLogger(); 
 consoleLogger.setErrorPrintStream(ps); 
 consoleLogger.setOutputPrintStream(ps); 
 consoleLogger.setMessageOutputLevel(Project.MSG_INFO); 

 p.init(); 
 p.addBuildListener(consoleLogger); 
 ProjectHelper helper = ProjectHelper.getProjectHelper(); 
 helper.parse(p, buildFile); 

 p.executeTarget(p.getDefaultTarget()); 

执行 sshexec 目标进行编译时,我总是得到类似

的输出消息
[sshexec] cd ...; ls ...; ....

它只打印我写的命令,但是远程机器的编译信息不能在控制台打印。并且一旦编译过程中出现错误,它仍然可以成功返回构建。
如何在控制台打印远程消息并得到错误结果?

【问题讨论】:

    标签: eclipse ant eclipse-plugin console


    【解决方案1】:

    好的,我只是用另一种方式解决了这个问题。 我使用 process=Runtime.getRuntime().exec("java -jar ant-launcher.jar -f build.xml") 来执行ant任务。但是记得启动两个线程来读取process.getInputStream()和process.getErrorStream()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      相关资源
      最近更新 更多