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

(process) Runtime.exec(cmd[]) ignores quotes around arguments (win)

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :

      Passing arguments to a process via Runtime.exec(cmd[]), any arguments with quotes (") around them lose the quotes if the String starts with a whitespace. See the steps to reproduce.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      The following simple classes reproduce:

      import java.io.BufferedReader;
      import java.io.InputStreamReader;

      public class RunMe
      {
         public static void main(String[] args)
            throws Exception
         {
            String[] commandArray =
               {
                  "java",
                  "-classpath",
                  ".",
                  "PrintArgs",
                  " \"arg 1\"",
               };
            Process p = Runtime.getRuntime().exec(commandArray);
                   
            StringBuffer stdout = new StringBuffer();
            
            InputStreamReader isr = new InputStreamReader(p.getInputStream());
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            
            while ((line = br.readLine()) != null)
            {
               stdout.append(line+"\n");
            }
            
            System.out.println(stdout);
         }
      }
      //------------------------------
      public class PrintArgs
      {
      public static void main(String[] args)
      {
      for (int i = 0; i < args.length; i++)
      {
      System.out.println("args["+i+"] = [" + args[i] + "]");
      }
      }
      }

      Observe the the last parameter in commandArray is surrounded by quotes and has a space in front of it.

      The output of running RunMe is:
      args[0] = [ arg]
      args[1] = [1]

      The quotes are getting lost. Removing the space in front of arg1 changes the output to this:
      args[0] = [arg 1]





      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Make sure you don't put spaces in front of your arguments :-)
      ###@###.### 2005-05-26 13:37:40 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                uta Alexey Utkin (Inactive)
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: