0

Hello, im trying to write to an external program and the inputs and outputs works fine for the first time that im printing the stdin. After this time the program look like it stuck.

Help Please.

Attachments
import java.io.*;
import java.util.*;

public class Main
{

	/**
     * @param args the command line arguments
	 */
		public static void main(String[] args)
	{
		// TODO code application logic here

		String s = null;

		try
		{


			String pmrFormulaFile = "/opt/ericsson/amos/moshell/commonjars/pm/FORMULA_RNC_H_1_0.txt";
			String pmrConfigurationFileStr = "/opt/ericsson/amos/moshell/commonjars/pm/CONFIG_RNC_H_1_0.txt";

			List<String> lineList = new ArrayList<String>();

			lineList.add("pmr -l /home/" + "roisht" + "/" + "RNC028" +
						 " -f  " + pmrFormulaFile + " -c " + pmrConfigurationFileStr +
						 " -m  " + "4");


			Process p = Runtime.getRuntime().exec("moshell");

			BufferedReader stdInput = new BufferedReader(new
				 InputStreamReader(p.getInputStream()));

			BufferedReader stdError = new BufferedReader(new
				 InputStreamReader(p.getErrorStream()));

			BufferedWriter stdOutput = new BufferedWriter(new
					OutputStreamWriter(p.getOutputStream()));



			stdOutput.write(lineList.get(0));
			stdOutput.newLine();
			stdOutput.flush();


			lineList.add("17");



			stdOutput.write(lineList.get(1));
			stdOutput.newLine();
			stdOutput.flush();




			lineList.add("18");

			stdOutput.write(lineList.get(2));
			stdOutput.newLine();
			stdOutput.flush();





			// read the output from the command
			System.out.println("Here is the standard output of the command:\n");
			while ((s = stdInput.readLine()) != null)
			{
				System.out.println(s);
			}


			// read any errors from the attempted command
			System.out.println("Here is the standard error of the command (if any):\n");
			while ((s = stdError.readLine()) != null)
			{
				System.out.println(s);
			}



			// In this part the program stucked


			lineList.add("18");

			stdOutput.write(lineList.get(2));
			stdOutput.newLine();
			stdOutput.flush();




			// read the output from the command
			System.out.println("Here is the standard output of the command:\n");
			while ((s = stdInput.readLine()) != null)
			{
				System.out.println(s);
			}

			// read any errors from the attempted command
			System.out.println("Here is the standard error of the command (if any):\n");
			while ((s = stdError.readLine()) != null)
			{
				System.out.println(s);
			}


		}
		catch (IOException e)
		{
			System.out.println("exception happened - here's what I know: ");
			e.printStackTrace();
			System.exit(-1);
		}




	}

}
3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by NormR1
0

Try debugging your program by adding println() statements to show where it is executing and how the variables are changing value.

0

post the error that was thrown when compile/running...

there is no error, it just get stucked immidiate after the first while ((s = stdInput.readLine()) != null) at the moment it should be null.

0

Try debugging your program by adding println() statements to show where it is executing and how the variables are changing value.

i tried that and i saw that stdin is never reached to null, and the program stucked at the time that the buffer supose to be empty.

0

Is it working ok now?

it does not work and i think i ound out the reason.
the readline is waiting to a new line and its not getting the null cause i didnt close the stdout. i cant close the stdout cause i want to use it after so ill have to think about somthing different.

thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.