使用以下代码在远程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中也发布了相同的问题,但没有回复。