Home » Eclipse Projects » DSDP - Target Management » How to run single command and capture output using RSE
| | |
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 |
David McKnight 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 #573587 is a reply to message #20564] |
Mon, 07 April 2008 21:08 |
David McKnight 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.>
|
|
|
Goto Forum:
Current Time: Mon Dec 30 16:53:28 GMT 2024
Powered by FUDForum. Page generated in 0.03788 seconds
|