public void executeRemoteCommand( String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) throws CoreException { IServer s = ServerCore.findServer(serverId); IShellService service = findShellService(s); try { if (singleUseShell == null || !singleUseShell.isActive()) { singleUseShell = service.launchShell(initialWorkingDirectory, environment, monitor); } else if (initialWorkingDirectory != null) { // allow for a null working directory to ensure no command is run here singleUseShell.writeToShell("cd " + initialWorkingDirectory); } singleUseShell.writeToShell(command); } catch (RuntimeException re) { String className = service.getClass().getName(); if (className.endsWith(".DStoreShellService")) { throw new CoreException( new Status( IStatus.ERROR, org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID, "no remote daemon installed. Please install a remote daemon or use an RSE server configured for ssh rather than dstore")); } } catch (SystemMessageException sme) { Status s2 = new Status( IStatus.ERROR, org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID, sme.getMessage(), sme); throw new CoreException(s2); } }
/** * Return a -1 if no idea what happened, or the actual status code from the shutdown command * * @param initialWorkingDirectory * @param command * @param environment * @param monitor * @param delay * @param exit * @return * @throws CoreException */ public int executeRemoteCommandGetStatus( String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor, int delay, boolean exit) throws CoreException { executeRemoteCommand(initialWorkingDirectory, command, environment, monitor); final String[] statusLine = new String[2]; // [0] is last, [1] is new final boolean[] done = new boolean[1]; done[0] = false; statusLine[0] = null; IHostShellOutputListener statusListener = new IHostShellOutputListener() { public void shellOutputChanged(IHostShellChangeEvent event) { IHostOutput[] lines = event.getLines(); for (int i = 0; i < lines.length; i++) { // shift if (!done[0]) { statusLine[0] = statusLine[1]; statusLine[1] = lines[i].getString(); System.out.println("RSEHostShellModel debug out: " + lines[i].getString()); } if (serverId.equals(statusLine[1])) // Then the real answer is the line before this one... statusLine[0] done[0] = true; } } }; singleUseShell.getStandardOutputReader().addOutputListener(statusListener); singleUseShell.writeToShell("echo $? && echo \"" + serverId + "\""); ThreadUtils.sleepFor(delay); if (exit && singleUseShell != null && singleUseShell.isActive()) { singleUseShell.exit(); singleUseShell = null; } String s = statusLine[0]; done[0] = true; // ensure a cleanup if (s != null) { try { Integer i = Integer.parseInt(s); return i.intValue(); } catch (NumberFormatException nfe) { } } Trace.trace( Trace.STRING_FINER, NLS.bind("Command {0} exited with status {1}", command, statusLine[0])); return -1; }
public void executeRemoteCommand( String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor, int delay, boolean exit) throws CoreException { executeRemoteCommand(initialWorkingDirectory, command, environment, monitor); ThreadUtils.sleepFor(delay); if (exit && singleUseShell != null) { singleUseShell.exit(); singleUseShell = null; } }
public IHostShell createStartupShell( String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) throws CoreException, SystemMessageException { resetStartupShell(); IServer s = ServerCore.findServer(serverId); IShellService service = findShellService(s); try { IHostShell hs = service.runCommand(initialWorkingDirectory, command, environment, monitor); listener = new IHostShellOutputListener() { public void shellOutputChanged(IHostShellChangeEvent event) { IHostOutput[] lines = event.getLines(); String[] lines2 = new String[lines.length]; for (int i = 0; i < lines.length; i++) { lines2[i] = lines[i].getString(); } writeToConsole(lines2); } }; startupShell = hs; startupShell.addOutputListener(listener); return hs; } catch (SystemMessageException sme) { throw sme; } catch (RuntimeException re) { throw new CoreException( new Status( IStatus.ERROR, org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID, re.getMessage(), re)); } }
public void resetStartupShell() { if (startupShell != null && startupShell.isActive()) { startupShell.exit(); startupShell = null; } }