JDK-4057560 : Input Stream is not available from exec'ed sub-process from java.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.2
  • Priority: P1
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1997-06-09
  • Updated: 1997-06-09
  • Resolved: 1997-06-09
Related Reports
Duplicate :  
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

Comments
EVALUATION This bug was not a duplicate. It should be closed as not a bug. I can't see how to change that in the bug information, so I'm just going to update the evaluation. Date: Mon, 9 Jun 1997 16:46:35 -0700 (PDT) From: Rohit Valia <rvalia@pacific> Subject: Re: BugId 4039120 : (P1/S3) Priority value changed from: 3 to: 1 To: Tom Rodriguez <never@boojum> Yes it does! I seem to remember having one version of of my C program which actually had the flush of the stdout but at the time the problem might have been the java program. Somewhere along the rev's I seem to have dropped the flush and adding that now fixed the problem. Thanks for your prompt response. If you need me to change status on the bug or something, let me know. Rohit > Hi. Your bug is unrelated to the bug you've marked it as a >duplicate of. In fact it's not a bug in the VM as far as I can tell. >Your test program is talking across a pipe using buffered I/O so your >putchars are just being buffered. If you add an fflush(stdout) after >the putchar then your program works. Do this solve your problem or is >there something else going on? > > tom > =================================================================== /\ Rohit Valia \\ \ Network Security Products Group \ \\ / Sun Microsystems, Inc. / \/ / / 2550, Garcia Ave, MPK17-204, / / \//\ Mountain View, CA 94043. \//\ / / / / /\ / Phone: (415) 786-5137 / \\ \ Fax: (415) 786-6137 \ \\ Email: ###@###.### \/
11-06-2004

PUBLIC COMMENTS See Also BugID: 4039120 Consider the code snippet: Process proc; PrintWriter out; String inputStr; out = p.getOutputStream(); out.println(inputStr); I suspect this does not pass mystring to the process. Please see Description for the full test programs.
10-06-2004