### Eclipse Workspace Patch 1.0 #P org.eclipse.rse.remotecdt Index: src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java,v retrieving revision 1.5 diff -u -r1.5 RemoteRunLaunchDelegate.java --- src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java 19 Sep 2006 21:57:14 -0000 1.5 +++ src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java 20 Oct 2006 08:36:07 -0000 @@ -55,6 +55,8 @@ private final static String SHELL_SERVICE = "shell.service"; //$NON-NLS-1$ private final static String FILE_SERVICE = "file.service"; //$NON-NLS-1$ + private final static String EXIT_CMD = "exit"; //$NON-NLS-1$ + private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$ /* * (non-Javadoc) @@ -259,8 +261,13 @@ protected Process remoteShellExec(ILaunchConfiguration config, String remoteCommandPath, String arguments) throws CoreException { - String remote_command = arguments == null ? spaceEscapify(remoteCommandPath) : + // The exit command is called to force the remote shell to close after our command + // is executed. This is to prevent a running process at the end of the debug session. + // See Bug 158786. + String real_remote_command = arguments == null ? spaceEscapify(remoteCommandPath) : spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$ + String remote_command = real_remote_command + CMD_DELIMITER + EXIT_CMD; + IShellService shellService = (IShellService) getConnectedRemoteService(config, SHELL_SERVICE); // This is necessary because runCommand does not actually run the command right now. Index: src/org/eclipse/rse/remotecdt/HostShellAdapter.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/HostShellAdapter.java,v retrieving revision 1.1 diff -u -r1.1 HostShellAdapter.java --- src/org/eclipse/rse/remotecdt/HostShellAdapter.java 19 Sep 2006 21:31:22 -0000 1.1 +++ src/org/eclipse/rse/remotecdt/HostShellAdapter.java 20 Oct 2006 08:36:07 -0000 @@ -48,6 +48,8 @@ hostShell.exit(); notifyAll(); try { + hostShellInput.close(); + hostShellError.close(); inputStream.close(); errorStream.close(); outputStream.close(); @@ -56,7 +58,7 @@ } } - public int exitValue() { + public synchronized int exitValue() { if(hostShell.isActive()) throw new IllegalThreadStateException(); // No way to tell what the exit value was. @@ -76,8 +78,30 @@ } public synchronized int waitFor() throws InterruptedException { - while(hostShell.isActive()) - wait(); + + while(hostShell.isActive()) { + try { + wait(1000); + } catch (InterruptedException e) { + // ignore because we're polling to see if shell is still active. + } + } + + try { + // Wait a second to try to get some more output from the target shell before closing. + wait(1000); + // Allow for the data from the stream to be read if it's available + if (inputStream.available() != 0 || errorStream.available() != 0) + throw new InterruptedException(); + + hostShellInput.close(); + hostShellError.close(); + inputStream.close(); + errorStream.close(); + outputStream.close(); + } catch (IOException e) { + // Ignore + } return 0; }