From 90932719b58b0e8ec33f4e3a7664b84d582e97b0 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 18 Sep 2024 18:36:52 +0200 Subject: [PATCH] Specify /D for cmd.exe to bypass the Command Processor Autorun directory This closes #272 --- .../codehaus/plexus/util/cli/shell/CmdShell.java | 2 +- .../codehaus/plexus/util/cli/CommandlineTest.java | 14 ++++++++------ .../plexus/util/cli/shell/BourneShellTest.java | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java index 47cc5154..2ce59c23 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java +++ b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java @@ -32,7 +32,7 @@ public class CmdShell extends Shell { public CmdShell() { setShellCommand("cmd.exe"); setQuotedExecutableEnabled(true); - setShellArgs(new String[] {"/X", "/C"}); + setShellArgs(new String[] {"/X", "/D", "/C"}); } /** diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java index dffead1c..6518c950 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -182,14 +182,15 @@ public void testGetShellCommandLineWindows() throws Exception { cmd.addArguments(new String[] {"a", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals(4, shellCommandline.length, "Command line size"); + assertEquals(5, shellCommandline.length, "Command line size"); assertEquals("cmd.exe", shellCommandline[0]); assertEquals("/X", shellCommandline[1]); - assertEquals("/C", shellCommandline[2]); + assertEquals("/D", shellCommandline[2]); + assertEquals("/C", shellCommandline[3]); String expectedShellCmd = "\"c:" + File.separator + "Program Files" + File.separator + "xxx\" a b"; expectedShellCmd = "\"" + expectedShellCmd + "\""; - assertEquals(expectedShellCmd, shellCommandline[3]); + assertEquals(expectedShellCmd, shellCommandline[4]); } /** @@ -204,15 +205,16 @@ public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception { cmd.addArguments(new String[] {"c:\\Documents and Settings\\whatever", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals(4, shellCommandline.length, "Command line size"); + assertEquals(5, shellCommandline.length, "Command line size"); assertEquals("cmd.exe", shellCommandline[0]); assertEquals("/X", shellCommandline[1]); - assertEquals("/C", shellCommandline[2]); + assertEquals("/D", shellCommandline[2]); + assertEquals("/C", shellCommandline[3]); String expectedShellCmd = "\"c:" + File.separator + "Program Files" + File.separator + "xxx\" \"c:\\Documents and Settings\\whatever\" b"; expectedShellCmd = "\"" + expectedShellCmd + "\""; - assertEquals(expectedShellCmd, shellCommandline[3]); + assertEquals(expectedShellCmd, shellCommandline[4]); } /** diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java index 945b0bda..c00d6471 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java @@ -205,8 +205,9 @@ public void testArgumentsWithsemicolon() { assertEquals("cmd.exe", lines[0]); assertEquals("/X", lines[1]); - assertEquals("/C", lines[2]); - assertEquals("\"--password ;password\"", lines[3]); + assertEquals("/D", lines[2]); + assertEquals("/C", lines[3]); + assertEquals("\"--password ;password\"", lines[4]); } /**