diff --git a/java/client/src/org/openqa/selenium/os/WindowsUtils.java b/java/client/src/org/openqa/selenium/os/WindowsUtils.java index a2a28cd6ab546..a531fd611c5eb 100644 --- a/java/client/src/org/openqa/selenium/os/WindowsUtils.java +++ b/java/client/src/org/openqa/selenium/os/WindowsUtils.java @@ -109,10 +109,14 @@ public static void kill(String[] cmdarray) throws Exception { * quote (\"?) */ // TODO We should be careful, in case Windows has ~1-ified the executable name as well - pattern.append("\"?.*?\\\\"); - pattern.append(executable.getName()); + pattern.append("(\"?.*?\\\\)?"); + String execName = executable.getName(); + pattern.append(execName); + if (!execName.endsWith(".exe")) { + pattern.append("(\\.exe)?"); + } pattern.append("\"?"); - for (String arg : cmdarray) { + for (int i = 1; i < cmdarray.length; i++) { /* * There may be a space, but maybe not (\\s?), may be a quote or maybe not (\"?), but then * turn on block quotation (as if *everything* had a regex backslash in front of it) with \Q. @@ -120,7 +124,7 @@ public static void kill(String[] cmdarray) throws Exception { * quotation. Now ignore a final quote if any (\"?) */ pattern.append("\\s?\"?\\Q"); - pattern.append(arg); + pattern.append(cmdarray[i]); pattern.append("\\E\"?"); } pattern.append("\\s*"); diff --git a/java/client/test/org/openqa/selenium/os/WindowsUtilsUnitTest.java b/java/client/test/org/openqa/selenium/os/WindowsUtilsUnitTest.java index 6f37006eb8b58..4245111950fea 100644 --- a/java/client/test/org/openqa/selenium/os/WindowsUtilsUnitTest.java +++ b/java/client/test/org/openqa/selenium/os/WindowsUtilsUnitTest.java @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Test; +import java.util.Arrays; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,6 +74,19 @@ public void testTaskKill() { assertFalse("taskkill should be found", "taskkill".equals(WindowsUtils.findTaskKill())); } + private void tryKill(String[] cmd) throws Exception { + CommandLine cl = new CommandLine(cmd); + cl.executeAsync(); + WindowsUtils.kill(cmd); + assertFalse("Should be able to kill " + Arrays.toString(cmd), cl.isRunning()); + } + + @Test + public void testKill() throws Exception { + tryKill(new String[]{"sleep.exe", "10"}); + tryKill(new String[]{"sleep", "10"}); + } + @Test public void testRegistry() { if (!WindowsUtils.thisIsWindows()) return;