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

Trailing space in input stream of Runtime.exec() in Java 2

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt

      Description



      Name: dbT83986 Date: 04/20/99


      Compile and run the following program on Windows NT 4.0 using
      Java full version "JDK-1.2-V"
      Classic VM (build JDK-1.2-V, native threads)

      import java.io.*;

      class Test
      {
      public static void main( String[] args )
      {
      try
      {
      Process p = Runtime.getRuntime().exec( "cmd /c echo hello" );
      BufferedReader reader = new BufferedReader(
      new InputStreamReader( p.getInputStream() ) );
      p.waitFor();
      String echo = reader.readLine();
      System.out.println( "\"" + echo + "\"" );
      }
      catch ( Exception e )
      {
      e.printStackTrace();
      }
      }
      }

      The output is "hello ". The expected output, which I get in
      JDK 1.1.x (inc. 1.1.8) is "hello". Where is the extra space from?
      (Review ID: 57217)
      ======================================================================

      Name: skT88420 Date: 07/22/99

      =20
      Java Version 1.2.2-W running on Windows NT 4.0

      When the Win32Process class constructs a single command string
      from the argv String array, an extra blank is appended after
      the last arg. This extra blank can be important e.g. with
      the cmd.exe builting command "echo".

      TEST CASE:
      The original test case from bug 4231349:

      import java.io.*;

      class Test {
          public static void main( String[] args ) {
      =09try {
      =09=09Process p =3D Runtime.getRuntime().exec( "cmd /c echo hello" );
      =09=09BufferedReader reader =3D new BufferedReader(
      =09=09=09new InputStreamReader( p.getInputStream() ) );
      =09=09p.waitFor();
      =09=09String echo =3D reader.readLine();
      =09=09System.out.println( "\"" + echo + "\"" );
      =09} catch ( Exception e ) {
      =09=09e.printStackTrace();
      =09}
          }
      }


      With jdk1.2.2, the test case prints "hello ", while jdk1.1.8
      prints "hello" (without the trailing blank).
      RELATED BUGS:
      4231349
      (Review ID: 88255)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            mmcclosksunw Michael Mccloskey (Inactive)
            Reporter:
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: