diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/shell/SshHostShell.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/shell/SshHostShell.java index 1032f553a3f..6ec2667564c 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/shell/SshHostShell.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/shell/SshHostShell.java @@ -17,6 +17,7 @@ * David McKnight (IBM) - [196301] Check that the remote encoding isn't null before using it * Martin Oberhuber (Wind River) - [204744] Honor encoding in SSH command input field * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable + * Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.shell; @@ -115,7 +116,8 @@ public class SshHostShell extends AbstractHostShell implements IHostShell { && !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047 ) { writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$ - } else if (SHELL_INVOCATION.equals(commandToRun)) { + } + if (SHELL_INVOCATION.equals(commandToRun)) { writeToShell(getPromptCommand()); } else if(commandToRun!=null && commandToRun.length()>0) { writeToShell(commandToRun); diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java index faf9979716d..9aa9bf90c0f 100644 --- a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 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 @@ -13,10 +13,11 @@ * * Contributors: * Martin Oberhuber (Wind River) - Adapted from LocalHostShell. - * Sheldon D'souza (Celunite) - Adapted from SshHostShell - * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells - * David McKnight (IBM) - [191599] Use the remote encoding specified in the host property page + * Sheldon D'souza (Celunite) - Adapted from SshHostShell + * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells + * David McKnight (IBM) - [191599] Use the remote encoding specified in the host property page * Martin Oberhuber (Wind River) - [194466] Fix shell terminated state when stream is closed + * Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied *******************************************************************************/ package org.eclipse.rse.internal.services.telnet.shell; @@ -75,7 +76,8 @@ public class TelnetHostShell extends AbstractHostShell implements IHostShell { && !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047 ) { writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$ - } else if (SHELL_INVOCATION.equals(commandToRun)) { + } + if (SHELL_INVOCATION.equals(commandToRun)) { writeToShell(getPromptCommand()); } else if(commandToRun!=null && commandToRun.length()>0) { writeToShell(commandToRun); diff --git a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/internal/services/shells/TerminalServiceHostShell.java b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/internal/services/shells/TerminalServiceHostShell.java index 5c1c2a1ff15..0ea2b75ae93 100644 --- a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/internal/services/shells/TerminalServiceHostShell.java +++ b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/internal/services/shells/TerminalServiceHostShell.java @@ -19,6 +19,7 @@ * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable * Anna Dushistova (MontaVista) - adapted from SshHostShell * Anna Dushistova (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService + * Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied *******************************************************************************/ package org.eclipse.rse.internal.services.shells; @@ -88,7 +89,8 @@ public class TerminalServiceHostShell extends AbstractHostShell { && !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047 ) { writeToShell("cd " + PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$ - } else if (SHELL_INVOCATION.equals(commandToRun)) { + } + if (SHELL_INVOCATION.equals(commandToRun)) { writeToShell(getPromptCommand()); } else if (commandToRun != null && commandToRun.length() > 0) { writeToShell(commandToRun); diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java index 0abfafe751a..81a1ed55307 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java @@ -131,57 +131,92 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase { } public void testLaunchShell() throws Exception { - IHostShell hostShell = shellService.launchShell("", new String[] {}, + Object[] allOutput = launchShell("", "echo test", new String[] {}); + boolean matchFound = false; + for (int i = 0; i < allOutput.length; i++) { + matchFound = ((IHostOutput) allOutput[i]).getString() + .equals("test"); + System.out.println(((IHostOutput) allOutput[i]).getString()); + if (matchFound) + break; + } + assertTrue(matchFound); + // now set working directory -- Linux only + allOutput = launchShell("/", "echo test", new String[] {}); + matchFound = false; + for (int i = 0; i < allOutput.length; i++) { + matchFound = ((IHostOutput) allOutput[i]).getString() + .equals("test"); + System.out.println(((IHostOutput) allOutput[i]).getString()); + if (matchFound) + break; + } + } + + public Object[] launchShell(String workingDirectory, String cmd, + String[] env) throws SystemMessageException, InterruptedException { + IHostShell hostShell = shellService.launchShell(workingDirectory, env, mon); assertNotNull(hostShell); assertNotNull(hostShell.getStandardOutputReader()); ShellOutputListener outputListener = new ShellOutputListener(); hostShell.addOutputListener(outputListener); // run command - hostShell.writeToShell("echo test"); + hostShell.writeToShell(cmd); hostShell.writeToShell("exit"); while (hostShell.isActive()) { - Thread.sleep(200); + Thread.sleep(1000); } Object[] allOutput = outputListener.getAllOutput(); + return allOutput; + } + + public void testRunCommand() throws Exception { + Object[] allOutput = runCommand("", "echo test", new String[] {}); boolean matchFound = false; for (int i = 0; i < allOutput.length; i++) { + System.out.println(((IHostOutput) allOutput[i]).getString()); matchFound = ((IHostOutput) allOutput[i]).getString() .equals("test"); if (matchFound) break; } - assertTrue(matchFound); + assertTrue("Failed without changing initial working directory",matchFound); + //set initial working directory -- Linux only + allOutput = runCommand("/", "echo test", new String[] {}); + matchFound = false; + for (int i = 0; i < allOutput.length; i++) { + System.out.println(((IHostOutput) allOutput[i]).getString()); + matchFound = ((IHostOutput) allOutput[i]).getString() + .equals("test"); + if (matchFound) + break; + } + assertTrue("Failed with changing initial working directory",matchFound); } - public void testRunCommand() throws Exception { + public Object[] runCommand(String workingDirectory, String cmd, String[] env) + throws SystemMessageException, InterruptedException { IHostShell hostShell = null; - hostShell = shellService.runCommand("", "echo test", new String[] {}, - mon); + hostShell = shellService.runCommand(workingDirectory, cmd, env, mon); ShellOutputListener outputListener = new ShellOutputListener(); hostShell.addOutputListener(outputListener); hostShell.writeToShell("exit"); assertNotNull(hostShell); assertNotNull(hostShell.getStandardOutputReader()); while (hostShell.isActive()) { - Thread.sleep(200); + Thread.sleep(1000); } Object[] allOutput = outputListener.getAllOutput(); - boolean matchFound = false; - for (int i = 0; i < allOutput.length; i++) { - matchFound = ((IHostOutput) allOutput[i]).getString() - .equals("test"); - if (matchFound) - break; - } - assertTrue(matchFound); + return allOutput; } public void testRunCommandViaHostShellProcessAdapter() throws Exception { IHostShell hostShell = null; + String commandSeparator = (shellSubSystem!=null)?shellSubSystem.getParentRemoteCmdSubSystemConfiguration() + .getCommandSeparator():"\r\n"; hostShell = shellService.runCommand("", "echo test" - + shellSubSystem.getParentRemoteCmdSubSystemConfiguration() - .getCommandSeparator() + " exit", new String[] {}, mon); + + commandSeparator + " exit", new String[] {}, mon); HostShellProcessAdapter p = null; try { p = new HostShellProcessAdapter(hostShell); @@ -196,7 +231,10 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase { boolean matchFound = false; try { while ((nextLine = bufferReader.readLine()) != null) { + System.out.println(nextLine); matchFound = nextLine.equals("test"); + if(matchFound) + break; } bufferReader.close(); } catch (IOException e) {