Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8136885

ProcessBuilder does not handle parentheses

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8u45
    • core-libs
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Executing an application to a path with a parentheses an NO spaces will result in an error:

      ... is not recognized as an internal or external command, operable program or batch file.

      When there is a space in the path, the ProcessBuilder execution will work, presumably because it automatically adds the necessary outer quotes, however without the space in the path or manually entering quotes, the operation will fail.

      It would be nice if ProcessBuilder treated the parentheses like a space, and add the outer quotes if required.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the following code (with C:\test\folderwith(1)\test.bat being a valid batch with a simple echo)

      ProcessBuilder processBuilder = new ProcessBuilder();
      List<String> command = new ArrayList<String>();
      command.add("C:\\test\\folderwith(1)\\test.bat");
      processBuilder.command(command);
      Process process = processBuilder.start();
      int result = process.waitFor();
      assertEquals(result, 0);


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The application is executed successfully.
      ACTUAL -
      The application fails to execute:
      'C:\\test\\folderwith' is not recognized as an internal or external command,
      operable program or batch file.

      Notice the missing remainder of the path.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      ProcessBuilder processBuilder = new ProcessBuilder();
      List<String> command = new ArrayList<String>();
      command.add("C:\\test\\folderwith(1)\\test.bat");
      processBuilder.command(command);
      Process process = processBuilder.start();
      int result = process.waitFor();
      assertEquals(result, 0); // fails
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Enclose the command in brackets manually, i.e.
      command.add("\"C:\\test\\folderwith(1)\\test.bat\"");

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: