Skip to content

Commit

Permalink
Specify /D for cmd.exe to bypass the Command Processor Autorun directory
Browse files Browse the repository at this point in the history
This closes #272
  • Loading branch information
sebthom authored and michael-o committed Sep 23, 2024
1 parent a5d1ab2 commit 9093271
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
}

/**
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand All @@ -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]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down

0 comments on commit 9093271

Please sign in to comment.