Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Target Management » How to run single command and capture output using RSE
How to run single command and capture output using RSE [message #19830] Mon, 31 March 2008 07:40 Go to next message
Timur Shipilov is currently offline Timur ShipilovFriend
Messages: 4
Registered: July 2009
Junior Member
Hi,

I'm adding remote projects support to dltk project. We are trying to use RSE
to launch remote interpreters. I have two questions to ask:
1. Is there a way to run a command in remote system's shell and capture only
its output without shell initialization and welcome messages?
2. How can one force shell to exit after execution of single command in
system independent way? Solution used in remotecdt looks like linux
dependent and doesn't work on my local windows machine.

Thanks,
Timur
Re: How to run single command and capture output using RSE [message #20112 is a reply to message #19830] Mon, 31 March 2008 15:53 Go to previous messageGo to next message
David McKnight is currently offline David McKnightFriend
Messages: 244
Registered: July 2009
Senior Member
Hi Timur,

I'm not sure whether this will work for you, as there have been some
inconsistent results in the past and differences depending on the protocol
used, but the attached example code may help with your questions.

Dave

"dltk-news" <timur@xored.com> wrote in message
news:fsq4i1$kah$1@build.eclipse.org...
> Hi,
>
> I'm adding remote projects support to dltk project. We are trying to use
> RSE
> to launch remote interpreters. I have two questions to ask:
> 1. Is there a way to run a command in remote system's shell and capture
> only
> its output without shell initialization and welcome messages?
> 2. How can one force shell to exit after execution of single command in
> system independent way? Solution used in remotecdt looks like linux
> dependent and doesn't work on my local windows machine.
>
> Thanks,
> Timur
>
>



Re: How to run single command and capture output using RSE [message #20564 is a reply to message #20112] Thu, 03 April 2008 20:55 Go to previous messageGo to next message
Denise Schmidt is currently offline Denise SchmidtFriend
Messages: 66
Registered: July 2009
Member
I am interested to see the example code but it is not readable in my web
browser. Could the example code be re-posted in plain text? Thanks.
Re: How to run single command and capture output using RSE [message #20583 is a reply to message #20564] Mon, 07 April 2008 21:08 Go to previous message
David McKnight is currently offline David McKnightFriend
Messages: 244
Registered: July 2009
Senior Member
Hi Denis,

Note that for simple commands it may be easier to use the
SimpleCommandOperation() utility. For dstore commands, you can use
SimpleCommandOperation(..., false) and avoid having to format out the extra
shell information.

I'll paste the code to the example I had here:

/*********************************************************** *********************
* Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
terms
* of the Eclipse Public License v1.0 which accompanies this distribution,
and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - Adapted original tutorial code to Open
RSE.
* David Dykstal (IBM) - formatting for tutorial
************************************************************ ********************/package samples.ui.actions;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.eclipse.jface.action.IAction;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.rse.core.model.IHost;import org.eclipse.rse.core.subsystems.ISubSystem;import org.eclipse.rse.shells.ui.RemoteCommandHelpers;import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile ;importorg.eclipse.rse.subsystems.shells.core.subsystems.IRe moteCmdSubSystem;import org.eclipse.rse.ui.SystemBasePlugin;import org.eclipse.swt.widgets.Shell;import org.eclipse.ui.IObjectActionDelegate;import org.eclipse.ui.IWorkbenchPart;/** * An action that runs a command to display the contents of a Jar file. * The plugin.xml file restricts this action so it only appears for .jarfiles. */public class TestSimpleCommandOperation implements IObjectActionDelegate { private List _selectedFiles; /** * Constructor for ShowJarContents. */ public TestSimpleCommandOperation() { _selectedFiles = new ArrayList(); } protected Shell getShell() { return SystemBasePlugin.getActiveWorkbenchShell(); } protected IRemoteFile getFirstSelectedRemoteFile() { if (_selectedFiles.size() > 0) { return (IRemoteFile) _selectedFiles.get(0); } return null; } protected ISubSystem getSubSystem() { return getFirstSelectedRemoteFile().getParentRemoteFileSubSystem(); } /* (non-Javadoc) * @seeorg.eclipse.ui.IActionDelegate#run(org.eclipse.jface.act ion.IAction) */ public void run(IAction action) { IRemoteFile selectedFile = getFirstSelectedRemoteFile(); TestRemoteCommandShellOperation op = newTestRemoteCommandShellOperation(getShell(), getRemoteCmdSubSystem(),selectedFile); op.run(); op.sendCommand("ls -l"); op.sendCommand("exit"); } public IRemoteCmdSubSystem getRemoteCmdSubSystem() { //get the Command subsystem associated with the current host IHost myHost = getSubSystem().getHost(); IRemoteCmdSubSystem[] subsys =RemoteCommandHelpers.getCmdSubSystems(myHost); for (int i = 0; i < subsys.length; i++) { if (subsys[i].getSubSystemConfiguration().supportsCommands()) { return subsys[i]; } } return null; } public void selectionChanged(org.eclipse.jface.action.IAction action,org.eclipse.jface.viewers.ISelection selection) { _selectedFiles.clear(); // store the selected jars to be used when running Iterator theSet = ((IStructuredSelection) selection).iterator(); while (theSet.hasNext()) { Object obj = theSet.next(); if (obj instanceof IRemoteFile) { _selectedFiles.add(obj); } } } public void setActivePart(IAction action, IWorkbenchPart targetPart) { }}/********************************************************* *********************** * Copyright (c) 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under theterms * of the Eclipse Public License v1.0 which accompanies this distribution,and is * available at http://www.eclipse.org/legal/epl-v10.html * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. * * Contributors: * {Name} (company) - description of contribution. ************************************************************ ********************/package samples.ui.actions;import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile ;importorg.eclipse.rse.subsystems.shells.core.model.RemoteCo mmandShellOperation;import org.eclipse.rse.subsystems.shells.core.model.RemoteOutput;im portorg.eclipse.rse.subsystems.shells.core.subsystems.IRemot eCmdSubSystem;import org.eclipse.swt.widgets.Shell;public class TestRemoteCommandShellOperation extends RemoteCommandShellOperation { private boolean _commandOutputStarted = false; public TestRemoteCommandShellOperation(Shell shell, IRemoteCmdSubSystemcmdSubSystem, IRemoteFile pwd) { super(shell, cmdSubSystem, pwd); } public void handleCommandFinished(String cmd) { // TODO Auto-generated method stub } public void handleOutputChanged(String command, Object output) { if (output instanceof RemoteOutput) { String text = ((RemoteOutput)output).getText(); System.out.println("updating output"+text); if (!_commandOutputStarted) { _commandOutputStarted = text.indexOf("BEGIN-END-TAG:") > 0; } else { if (text.indexOf("BEGIN-END-TAG:") > 0){ _commandOutputStarted = false; } else { processOutput(text); } } } } private void processOutput(String text) { System.out.println("line = " + text); }}"Denise Schmidt" <denise.schmidt@lmco.com> wrote in messagenews:1526240004450a851caa2e4508c808eb$1@www.eclipse.org...>I am interested to see the example code but it is not readable in my webbrowser. Could the example code be re-posted in plain text? Thanks.>
Re: How to run single command and capture output using RSE [message #573344 is a reply to message #19830] Mon, 31 March 2008 15:53 Go to previous message
David McKnight is currently offline David McKnightFriend
Messages: 244
Registered: July 2009
Senior Member
Hi Timur,

I'm not sure whether this will work for you, as there have been some
inconsistent results in the past and differences depending on the protocol
used, but the attached example code may help with your questions.

Dave

"dltk-news" <timur@xored.com> wrote in message
news:fsq4i1$kah$1@build.eclipse.org...
> Hi,
>
> I'm adding remote projects support to dltk project. We are trying to use
> RSE
> to launch remote interpreters. I have two questions to ask:
> 1. Is there a way to run a command in remote system's shell and capture
> only
> its output without shell initialization and welcome messages?
> 2. How can one force shell to exit after execution of single command in
> system independent way? Solution used in remotecdt looks like linux
> dependent and doesn't work on my local windows machine.
>
> Thanks,
> Timur
>
>



Re: How to run single command and capture output using RSE [message #573549 is a reply to message #20112] Thu, 03 April 2008 20:55 Go to previous message
Denise Schmidt is currently offline Denise SchmidtFriend
Messages: 66
Registered: July 2009
Member
I am interested to see the example code but it is not readable in my web
browser. Could the example code be re-posted in plain text? Thanks.
Re: How to run single command and capture output using RSE [message #573587 is a reply to message #20564] Mon, 07 April 2008 21:08 Go to previous message
David McKnight is currently offline David McKnightFriend
Messages: 244
Registered: July 2009
Senior Member
Hi Denis,

Note that for simple commands it may be easier to use the
SimpleCommandOperation() utility. For dstore commands, you can use
SimpleCommandOperation(..., false) and avoid having to format out the extra
shell information.

I'll paste the code to the example I had here:

/*********************************************************** *********************
* Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
terms
* of the Eclipse Public License v1.0 which accompanies this distribution,
and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - Adapted original tutorial code to Open
RSE.
* David Dykstal (IBM) - formatting for tutorial
************************************************************ ********************/package samples.ui.actions;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.eclipse.jface.action.IAction;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.rse.core.model.IHost;import org.eclipse.rse.core.subsystems.ISubSystem;import org.eclipse.rse.shells.ui.RemoteCommandHelpers;import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile ;importorg.eclipse.rse.subsystems.shells.core.subsystems.IRe moteCmdSubSystem;import org.eclipse.rse.ui.SystemBasePlugin;import org.eclipse.swt.widgets.Shell;import org.eclipse.ui.IObjectActionDelegate;import org.eclipse.ui.IWorkbenchPart;/** * An action that runs a command to display the contents of a Jar file. * The plugin.xml file restricts this action so it only appears for .jarfiles. */public class TestSimpleCommandOperation implements IObjectActionDelegate { private List _selectedFiles; /** * Constructor for ShowJarContents. */ public TestSimpleCommandOperation() { _selectedFiles = new ArrayList(); } protected Shell getShell() { return SystemBasePlugin.getActiveWorkbenchShell(); } protected IRemoteFile getFirstSelectedRemoteFile() { if (_selectedFiles.size() > 0) { return (IRemoteFile) _selectedFiles.get(0); } return null; } protected ISubSystem getSubSystem() { return getFirstSelectedRemoteFile().getParentRemoteFileSubSystem(); } /* (non-Javadoc) * @seeorg.eclipse.ui.IActionDelegate#run(org.eclipse.jface.act ion.IAction) */ public void run(IAction action) { IRemoteFile selectedFile = getFirstSelectedRemoteFile(); TestRemoteCommandShellOperation op = newTestRemoteCommandShellOperation(getShell(), getRemoteCmdSubSystem(),selectedFile); op.run(); op.sendCommand("ls -l"); op.sendCommand("exit"); } public IRemoteCmdSubSystem getRemoteCmdSubSystem() { //get the Command subsystem associated with the current host IHost myHost = getSubSystem().getHost(); IRemoteCmdSubSystem[] subsys =RemoteCommandHelpers.getCmdSubSystems(myHost); for (int i = 0; i < subsys.length; i++) { if (subsys[i].getSubSystemConfiguration().supportsCommands()) { return subsys[i]; } } return null; } public void selectionChanged(org.eclipse.jface.action.IAction action,org.eclipse.jface.viewers.ISelection selection) { _selectedFiles.clear(); // store the selected jars to be used when running Iterator theSet = ((IStructuredSelection) selection).iterator(); while (theSet.hasNext()) { Object obj = theSet.next(); if (obj instanceof IRemoteFile) { _selectedFiles.add(obj); } } } public void setActivePart(IAction action, IWorkbenchPart targetPart) { }}/********************************************************* *********************** * Copyright (c) 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under theterms * of the Eclipse Public License v1.0 which accompanies this distribution,and is * available at http://www.eclipse.org/legal/epl-v10.html * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. * * Contributors: * {Name} (company) - description of contribution. ************************************************************ ********************/package samples.ui.actions;import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile ;importorg.eclipse.rse.subsystems.shells.core.model.RemoteCo mmandShellOperation;import org.eclipse.rse.subsystems.shells.core.model.RemoteOutput;im portorg.eclipse.rse.subsystems.shells.core.subsystems.IRemot eCmdSubSystem;import org.eclipse.swt.widgets.Shell;public class TestRemoteCommandShellOperation extends RemoteCommandShellOperation { private boolean _commandOutputStarted = false; public TestRemoteCommandShellOperation(Shell shell, IRemoteCmdSubSystemcmdSubSystem, IRemoteFile pwd) { super(shell, cmdSubSystem, pwd); } public void handleCommandFinished(String cmd) { // TODO Auto-generated method stub } public void handleOutputChanged(String command, Object output) { if (output instanceof RemoteOutput) { String text = ((RemoteOutput)output).getText(); System.out.println("updating output"+text); if (!_commandOutputStarted) { _commandOutputStarted = text.indexOf("BEGIN-END-TAG:") > 0; } else { if (text.indexOf("BEGIN-END-TAG:") > 0){ _commandOutputStarted = false; } else { processOutput(text); } } } } private void processOutput(String text) { System.out.println("line = " + text); }}"Denise Schmidt" <denise.schmidt@lmco.com> wrote in messagenews:1526240004450a851caa2e4508c808eb$1@www.eclipse.org...>I am interested to see the example code but it is not readable in my webbrowser. Could the example code be re-posted in plain text? Thanks.>
Previous Topic:Questions about remote execution
Next Topic:Questions about remote execution
Goto Forum:
  


Current Time: Mon Dec 30 16:53:28 GMT 2024

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

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

Back to the top