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

Input Stream is not available from exec'ed sub-process from java.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Duplicate
    • Affects Version/s: 1.1.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description


      Attached are two programs. Compile the C program and the java program. Then run the java program with the C program as the argument. This causes the java program to exec the C program. The user input is then fed to the C program But it never gets to the C program for some reason. Your help would be appreciated.

      Rohit

      /**************************************************************************/
      /*------ test.c ------ C program --- simple program to print uppercase letters to lowercase*/
      /**************************************************************************/

      #include <stdio.h>
      #include <ctype.h>

      main() {
       int c;
      while((c = getchar()) != EOF) {
      putchar(tolower(c));
      }
      return 0;
      }
      /**************************************************************************/
      /*---- TestExec.java --- Java program for execing C program*/
      /* Usage java TestExec c_program_name */
      /**************************************************************************/
      import java.io.DataInputStream;
      import java.io.DataOutputStream;
      import java.io.OutputStream;
      import java.io.PrintWriter;
      import java.io.InputStreamReader;
      import java.io.BufferedReader;
      import java.io.IOException;

      public class TestExec {

      public static void main(String argv[]) {
      Runtime rt = Runtime.getRuntime();
      Process proc = null;
      BufferedReader in = null;
      //DataOutputStream out = null;
      PrintWriter out = null;
      try {
      proc = rt.exec(argv);
      if (null == proc) {
      System.out.println("Process exec fails");
      System.exit(1);
      }
      in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
      out = new PrintWriter(proc.getOutputStream());
      if (null == in) {
      System.out.println("Input Stream is null");
      System.exit(1);
      }
      if (null == out) {
      System.out.println("Output Stream is null");
      System.exit(1);
      }
      }
      catch (IOException e) {
      System.out.println("Process exec fails: " + e.getMessage());
      System.exit(1);
      }

      String inputStr = null;
      String outputStr = null;
      DataInputStream systemIn = new DataInputStream(System.in);
      System.out.print("Input: ");
      try {
      inputStr = systemIn.readLine();
      while (! inputStr.equals("quit")) {
      out.println(inputStr);
      out.flush();
      outputStr = in.readLine();
      System.out.println("Output: " + outputStr);
      System.out.print("Input: ");
      inputStr = systemIn.readLine();
      }
      }
      catch (IOException ie) {
      System.out.println("Interaction Error: " + ie.getMessage());
      }
      System.out.println("Viola!");
      }
      }

      rohit.valia@Eng 1997-06-09

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: