Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java EclipseRCP:在自定义控制台中运行系统命令并打印输出_Java_Eclipse_Eclipse Plugin_Eclipse Rcp - Fatal编程技术网

Java EclipseRCP:在自定义控制台中运行系统命令并打印输出

Java EclipseRCP:在自定义控制台中运行系统命令并打印输出,java,eclipse,eclipse-plugin,eclipse-rcp,Java,Eclipse,Eclipse Plugin,Eclipse Rcp,通过使用以下代码扩展IOConsole,我在eclipse中创建了一个自定义控制台 IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); IOConsole console = new MyConsole("My Custom Console", null); consoleManager.addConsoles(new IConsole[] { console }); 控制台创建正确,

通过使用以下代码扩展IOConsole,我在eclipse中创建了一个自定义控制台

IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
IOConsole console = new MyConsole("My Custom Console", null);
consoleManager.addConsoles(new IConsole[] { console });
控制台创建正确,我可以在RCP应用程序中显示的控制台列表中查看控制台

我想运行一个系统命令,并想在REALTIME中关联自定义控制台中的输出。我已经编写了下面的代码,但它似乎不起作用

ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsole[] consoles = plugin.getConsoleManager().getConsoles();
for (IConsole iConsole : consoles) {
    if (iConsole instanceof MyConsole) {
        console = (MyConsole) iConsole;
        break;
    }
}
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("mvn --version");
console.setInputStream(process.getInputStream());

有什么建议吗?

您可以使用一个单独的
线程,您可以:

  • 使用
    IOConsole\newOutputStream()
  • 从正在运行的进程中读取
    InputStream
    ,并使用前面提到的
    outputStream
    在控制台中写入字节,直到进程退出

您可以使用一个单独的
线程
,其中您可以:

  • 使用
    IOConsole\newOutputStream()
  • 从正在运行的进程中读取
    InputStream
    ,并使用前面提到的
    outputStream
    在控制台中写入字节,直到进程退出

我知道可能有点晚了,但最简单的方法是创建一个外部启动配置,设置正确的设置,运行它,然后稍后删除它。与his一样,控制台将自动更新,您可以取消执行等。 更多有关:

基本上:

ILaunchManager=DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType programType=管理器 .getLaunchConfigurationType(IExternalToolConstants.ID\程序\启动\配置\类型)


我知道可能有点太晚了,但最简单的方法是创建一个外部启动配置,设置适当的设置,运行它,然后稍后删除它。与his一样,控制台将自动更新,您可以取消执行等。 更多有关:

基本上:

ILaunchManager=DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType programType=管理器 .getLaunchConfigurationType(IExternalToolConstants.ID\程序\启动\配置\类型)


我已经尝试使用下面的代码来做同样的事情<代码>代码
(Runtime Runtime=Runtime.getRuntime();Process Process=Runtime.exec(“python”/*command.getCommand()*/);console.setInputStream(Process.getInputStream());IOConsoleOutputStream newOutputStream=console.newOutputStream();newOutputStream.setActivateOnWrite(true);而(Process.isAlive()){IOUtils.copy(process.getInputStream(),newOutputStream);})但它只是在尝试使用IOUtils.copy()将InputStream复制到OutputStream时无限期地卡住了。我做错了什么吗?感谢您,我已经尝试使用以下代码来做同样的事情。
code
(Runtime Runtime=Runtime.getRuntime();process process=Runtime.exec(“python”/*command.getCommand()*/);console.setInputStream(process.getInputStream());IOConsoleOutputStream newOutputStream=console.newOutputStream();newOutputStream.setActivateOnWrite(true);while(process.isAlive()){IOUtils.copy(process.getInputStream(),newOutputStream);}”但是它在尝试使用IOUtils.copy()将InputStream复制到OutputStream时被无限期地卡住了。我做错什么了吗?提前谢谢
        ILaunchConfiguration cfg = programType.newInstance(null, "YourCommandName");
        ILaunchConfigurationWorkingCopy wc = cfg.getWorkingCopy();
        wc.setAttribute(IExternalToolConstants.ATTR_LOCATION, "${system_path:" + systemCommand+ "}");
        wc.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, directoryToStartFrom);
        wc.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, parametersToPass);
        cfg = wc.doSave();
        cfg.launch(ILaunchManager.RUN_MODE, null, false, true);
        cfg.delete();