Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Target Management » How can I get only the output of remote commands ?
How can I get only the output of remote commands ? [message #570963] Thu, 06 December 2007 03:01
supertat is currently offline supertatFriend
Messages: 3
Registered: July 2009
Junior Member
Hello.
I would like to use RSE API to execute remote commands and get their
result strings.
However, as far as I tried, I cannot find any way to get only the result
of the commands, that is, not including remote host's login greeting
message nor shell prompt.
I appreciate if you could tell me how to do that.

---
Here is what I tried:

(for given IHost)
IRemoteCmdSubSystem cmdSS = RemoteCommandHelpers.getCmdSubSystem(host);
String cmdStr = "ls -ltr";

(option 1) using IShellService#launchShell(), IShellService#runCommand()
------------------------------------------------------------ ---------------IShellService
shellService = ((IShellServiceSubSystem) cmdSS).getShellService();
String[] environment = new String[1];
environment[0] = "AAA=BBB";
String workDir = ".";
IHostShell hostShell = shellService.runCommand(initialWorkingDirectory,
cmdStr, environment, new NullProgressMonitor());
hostShell.addOutputListener(new StdOutOutputListener());
IHostShellOutputReader reader = hostShell.getStandardOutputReader();
IHostOutput hostOutput = reader.readLine();
while( hostOutput !=null) {
System.out.println(hostOutput.getString());
hostOutput = reader.readLine();
}

public class StdOutOutputListener implements IHostShellOutputListener {
public void shellOutputChanged(IHostShellChangeEvent event) {
}
}
------------------------------------------------------------ ---------------

(option 2) using IRemoteCmdSubSystem#runCommand()
------------------------------------------------------------ ---------------Object[]
result = cmdss.runCommand(cmdStr, null, false, new NullProgressMonitor());
if (result.length > 0 && result[0] instanceof IRemoteCommandShell) {
IRemoteCommandShell cs = (IRemoteCommandShell) result[0];
while (cs.isActive()) {
Thread.sleep(1000);
}

Object[] output = cs.listOutput();

for (int i = 0; i < output.length; i++) {
if (output[i] instanceof IRemoteOutput) {
System.out.println(((IRemoteOutput) output[i]).getText());
}
}
cmdSS.removeShell(cs);
}
------------------------------------------------------------ ---------------

(option 3) using SimpleCommandOperation#runCommand()
------------------------------------------------------------ ---------------SimpleCommandOperation
operation = new SimpleCommandOperation(cmdSS, workDir, true);
operation.runCommand(cmdStr, true);
String line = operation.readLine(true);
while (line != null) {
System.out.println(line);
line = operation.readLine(true);
}
------------------------------------------------------------ ---------------


For all the options above, the output strings are like this
------------------------------------------------------------ ---------------Last
login: Thu Dec 6 12:19:17 2007 from XXX.XX.XX.XXX
ls -ltr

echo $PWD'>'

[aaa@ms ~]$ ls -ltr
total 92
drwxr-xr-x 12 onishi sim 4096 Apr 20 2007 aa.txt
drwxr-xr-x 2 onishi sim 4096 Jun 12 16:14 bb.txt
[aaa@ms ~]$
[aaa@ms ~]$ echo $PWD'>'
/home/aaa>
------------------------------------------------------------ ---------------

What I would like to get is only this part of the above.
------------------------------------------------------------ ---------------total
92
drwxr-xr-x 12 onishi sim 4096 Apr 20 2007 aa.txt
drwxr-xr-x 2 onishi sim 4096 Jun 12 16:14 bb.txt
------------------------------------------------------------ ---------------

Thanks in advance.
Previous Topic:Target Communication Framework (TCF) available on bugzilla
Next Topic:scp / sftp
Goto Forum:
  


Current Time: Sat Nov 29 01:43:03 GMT 2014

Powered by FUDForum. Page generated in 0.02579 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software