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

Runtime.exec(String) does not parse quotes correctly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.2.2, 1.3.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt, windows_2000

      Description



      Name: stC104175 Date: 08/23/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)



      Runtime.exec(String) and Runtime.exec(String, String[]) do not consider the
      significance of single and double quote characters when parsing the command-line
      string. Right now they parse "xterm -T 'My title' -e ls" as follows:

      xterm
      -T
      'My
      title'
      -e
      ls

      such that each line denotes another element in the array ARGV[]. Instead, the
      above String should be parsed as:

      xterm
      -T
      My title
      -e
      ls

      Another thing worth noting is that this parsing behavior should be different
      under Windows and Unix-based machines as Unix-based machines accept single and
      double quotes equaly and Windows-based machines only accept double-quotes.
      If you would like me to provide you with the source-code to correct this bug,
      please contact me.
      (Review ID: 107860)
      ======================================================================

      Name: krC82822 Date: 03/14/2001


      >java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      exec cannot handle commands with "-" parameters.
      Below code executes nbtstat with -n parameter.
      Output dataset does not get updated with command output.
      Command works under C++ and NT Command Prompt.

      button12.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
              Runtime r = Runtime.getRuntime();
      try {
      r.exec("c:\\windows\\system32\\nbtstat -n > c:\\temp\\tmp.rpt");
      }
      catch (java.io.IOException e)
      { System.out.println("Got exception on button Nbtstat Names " +
      e);
      e.printStackTrace();
      }
            }
          });



      Commands with "/" parameters work fine:
      Below code executes mem with /d parameter.
       
      button11.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
              Runtime r = Runtime.getRuntime();
      try {
      r.exec("c:\\windows\\system32\\mem.exe /d > c:\\temp\\tmp.rpt");
      callWord();
      }
      catch (java.io.IOException e)
      { System.out.println("Got exception on button Memory Debug " +
      e);
      e.printStackTrace();
      }
            }
          });


      Workaround is to place command in a script file:

       button12.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
              Runtime r = Runtime.getRuntime();
      try {
      r.exec("c:\\joe\\java\\bin\\nbtstat_n.bat");
      // r.exec("c:\\windows\\system32\\nbtstat -n > c:\\temp\\tmp.rpt");
      callWord();
      }
      catch (java.io.IOException e)
      { System.out.println("Got exception on button Nbtstat Names " +
      e);
      e.printStackTrace();
      }
            }
          });



      where nbtstat_n.bat contains:

      c:\\windows\\system32\\nbtstat -n > c:\\temp\\tmp.rpt
      (Review ID: 118798)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kkladkosunw Konstantin Kladko (Inactive)
              Reporter:
              stompkinsunw Sean Tompkins (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: