1

使用以下代码在远程 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论坛上发布了同样的问题,但没有回应。

4

0 回答 0