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

specify encoding of arguments for external program call

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u40
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      I want to start an external program with an argument which contains german letters, like this:

          ProcessBuilder pb = new ProcessBuilder("myScript.sh", "argument_with_letters_äöü");
          Process p = pb.start();

      My JVM is started with encoding ISO 8859-15. The external program 'myScript.sh' however expects UTF-8.

      JUSTIFICATION :
      There is no way to specify encoding of the arguments, the arguments instead are encoded in the default encoding of the JVM.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I wish a method probably called 'setArgumentEncoding', which could be used like this:
      ProcessBuilder pb = new ProcessBuilder("myScript.sh", "argument_with_letters_äöü");
      pb.setArgumentEncoding("UTF-8"); // encodes the arguments as UTF-8
      Process p = pb.start();
      ACTUAL -
      There is no possibility to set the encoding. Instead the arguments are encoded in the default encoding of the JVM.

      ---------- BEGIN SOURCE ----------
      I don't hava a test case. This is a feature request, not a bug report.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is a suggestion for a workaround solution for the Unix operating system, namely to call the unix program 'xargs' instead of myScript.sh directly. Then get the outputStream before arguments are sent an encode them approriate. See example:

      // xargs -0 expects arguments on stdin separated by NUL characters
      ProcessBuilder pb = new ProcessBuilder("xargs", "-0", "myScript.sh");
      pb.environment().put("LANG", "de_DE.UTF-8"); // or whatever locale you require
      Process p = pb.start();
      OutputStream out = p.getOutputStream();
      out.write("argument_with_letters_äöü".getBytes("UTF-8")); // convert to UTF-8
      out.write(0); // NUL terminator
      out.close();

            rriggs Roger Riggs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: