Opening remote terminal programmatically in eclipse terminals view and execute shell commands programmatically in it

戏子无情 提交于 2019-12-08 05:11:19

问题


Using the below code to execute shell commands in remote shell and can able to read the command outputs:

    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);

But how I do the same thing in remote terminal which opens up in Terminals view?

Also posted the same question in eclipse forum but no response.

来源:https://stackoverflow.com/questions/38871861/opening-remote-terminal-programmatically-in-eclipse-terminals-view-and-execute-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!