Need example code snippet to open remote terminal and execute shell commands programmatically [message #1739730] |
Thu, 04 August 2016 12:00 |
Chandrayya Kumarswamimath Messages: 26 Registered: August 2010 Location: Bangalore |
Junior Member |
|
|
I am using the below code to open a remote terminal and execute a shell command in it.
TerminalsUI terminalsUI = TerminalsUI.getInstance();
TerminalViewer viewer = terminalsUI.activateTerminalsView();
CTabItem tab = viewer.getTabFolder().createTabItem(TerminalServiceHelper.getTerminalSubSystem(conn).getHost(), "");
TerminalElement element = TerminalServiceHelper.createTerminalElement(tab,
TerminalServiceHelper.getTerminalSubSystem(conn));
TerminalServiceHelper.getTerminalSubSystem(conn).addChild(element);
ITerminalShell lol = element.getTerminalShell();
TerminalShellService fdf = (TerminalShellService)RSEHelper.getConnectedRemoteShellService(conn, null);
SshTerminalService shelll = (SshTerminalService)fdf.getAdapter(ITerminalService.class);
element.setTerminalShell((ITerminalShell)shelll);
shelll.launchTerminal(null, null, new String[] {}, "", "ls -l", null);
This is opening the remote terminal in "Terminals" view with the content:
Last login: Wed Aug 17 11:14:33 2016 from 10.X.X.X
root@moron:~#
Also command ls -l was not executed and shown in the newly opened terminal may be because of the exception:
java.lang.ClassCastException: org.eclipse.rse.internal.services.ssh.terminal.SshTerminalService cannot be cast to org.eclipse.rse.services.terminals.ITerminalShell
at the line: element.setTerminalShell((ITerminalShell)shelll);
Question:
The above code snippet gives warning as "Discouraged access" at many places.
Please can any one post the recommended code snippet that can be used to open a remote terminal programmatically and execute commands in it programmatically?
[Updated on: Thu, 04 August 2016 12:01] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03299 seconds