Skip to main content

Problem in sending inputs to a Process.

2 replies [Last post]
Joined: 2008-12-08

Hi All,

I am trying to execute a RPM file from Java using the code shown below.

1)Process proc = Runtime.getRuntime().exec(command);
//Here command is "/bin/sh -c /usr/CI/sample-rpm.bin"
2) read the input stream of the Process in a separate thread and print it to System.out
3) Write the user input from to the output stream of the Process in a separate thread.

This RPM is interactive. It first shows a license agreement and waits for the user input.
I am able to read from the inputstream of this Process and redirect it to System.out. My problem is in sending the user response to this process. I tried accessing the outputstream of this process and writing the user response to this outputstream. But, this does not work. We are using JDK 1.5.

Has anybody faced this problem before? Any inputs would be really helpful.

Many many thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-02-09

Have you tried closing the output stream of the process when you've finished writing to it?


Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("some program");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

Joined: 2008-12-08

Thanks for the reply.

We were using the println() method of PrintWriter to write to the output stream of the Process. This was creating problems. We later wrote a new line character to the Process's output stream at the end, and it worked.