From 5aa266c4ce9923c32b20d17607ac8566681c2c54 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Fri, 27 Oct 2006 02:10:27 +0000 Subject: [PATCH] Add sample code for running invisible commands --- .../samples/ui/actions/ShowJarContents.java | 70 +++++++++++++++---- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java b/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java index 5cde4dafd3d..d2e58ef738f 100644 --- a/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java +++ b/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java @@ -16,17 +16,22 @@ package samples.ui.actions; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.files.ui.actions.SystemAbstractRemoteFilePopupMenuExtensionAction; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput; import org.eclipse.rse.services.shells.IHostOutput; import org.eclipse.rse.services.shells.IHostShell; import org.eclipse.rse.services.shells.IHostShellChangeEvent; import org.eclipse.rse.services.shells.IHostShellOutputListener; +import org.eclipse.rse.services.shells.IShellService; import org.eclipse.rse.shells.ui.RemoteCommandHelpers; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; -import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IServiceCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystem; /** * An action that runs a command to display the contents of a Jar file. @@ -50,7 +55,9 @@ public class ShowJarContents extends SystemAbstractRemoteFilePopupMenuExtensionA try { runCommand(cmdToRun); } catch(Exception e) { - MessageDialog.openError(getShell(), e.getClass().getName(), e.getLocalizedMessage()); + String excType = e.getClass().getName(); + MessageDialog.openError(getShell(), excType, excType+": "+e.getLocalizedMessage()); //$NON-NLS-1$ + e.printStackTrace(); } } @@ -70,29 +77,64 @@ public class ShowJarContents extends SystemAbstractRemoteFilePopupMenuExtensionA { IRemoteCmdSubSystem cmdss = getRemoteCmdSubSystem(); if (cmdss!=null && cmdss.isConnected()) { - //Option A: run the command invisibly + //Option A: run the command invisibly through SubSystem API //runCommandInvisibly(cmdss, command); - //Option B: run the command in a visible shell + //Option B: run the command invisibly through Service API + //runCommandInvisiblyService(cmdss, command); + //Option C: run the command in a visible shell RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss); //$NON-NLS-1$ } else { MessageDialog.openError(getShell(), "No command subsystem", "Found no command subsystem"); } } + + public static class StdOutOutputListener implements IHostShellOutputListener { + public void shellOutputChanged(IHostShellChangeEvent event) { + IHostOutput[] lines = event.getLines(); + for(int i=0; i0 && result[0] instanceof IServiceCommandShell) { - IServiceCommandShell scs = (IServiceCommandShell)result[0]; - IHostShell hs = scs.getHostShell(); - hs.addOutputListener(new IHostShellOutputListener() { - public void shellOutputChanged(IHostShellChangeEvent event) { - IHostOutput[] lines = event.getLines(); - for(int i=0; i0 && result[0] instanceof IRemoteCommandShell) { + IRemoteCommandShell cs = (IRemoteCommandShell)result[0]; + while (cs.isActive()) { + Thread.sleep(1000); + } + Object[] output = cs.listOutput(); + for (int i=0; i