在eclipse终端中以编程方式打开远程终端,并以编程方式执行shell命令

时间:2016-08-10 11:12:48

标签: eclipse eclipse-plugin eclipse-rcp eclipse-cdt eclipse-rse

使用以下代码在远程shell中执行shell命令,并且能够读取命令输出:

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        IStructuredSelection sel = (IStructuredSelection)window.getSelectionService().getSelection();
        RemoteProcessImpl ele = (RemoteProcessImpl)sel.getFirstElement();
        IHost conn = ele.getSystemConnection();
        IRemoteCmdSubSystem cmdSS = RemoteCommandHelpers.getCmdSubSystem(conn);
        Object[] obs = null;
        RemoteOutput fe = null;
        try {
            cmdSS.checkIsConnected(null);
        } catch (SystemMessageException e2) {
            e2.printStackTrace();
        }
        try {
            cmdSS.initializeSubSystem(null);
        } catch (SystemMessageException e1) {
            e1.printStackTrace();
        }
        RemoteCommandShell shell = null;
        try {
            shell = (RemoteCommandShell)cmdSS.getDefaultShell();
        } catch (Exception e) {
            e.printStackTrace();
        }
        shell.removeOutput();
        cmdSS.sendCommandToShell("ls -l", shell, null);
        Thread.sleep(1000);
        obs = new Object[shell.getRoots().length];
        obs = shell.getRoots();
        for (int i = 0; i < obs.length; i++) {
            fe = (RemoteOutput)obs[i];
            String op1 = fe.getText();
            System.out.println(op1);
        }
        command.setLength(0);

但我如何在终端视图中打开的远程终端中做同样的事情?

eclipse forum中也发布了相同的问题,但没有回复。

0 个答案:

没有答案