So I posted this problem over in
java Intermediate and have gotten no reposnse, so as a last effort I'm posting it here which is where it seems I should have posted in the first place. Sorry if this seems like cross posting however I did not receive an answer from anyone over there and maybe this problem is too advanced for them...
Here is the issue. My java program starts and launches an external program. I get the inputstream and outputstream of that process to play with. I can pipe all the inputstream information to a textarea just fine... however... its when i want to give input to the outputstream that the problem occurs. I believe I'm just thinking of this the wrong way and am coming here for help.
Also if anyone looking at this code can knows how I can differentiate from a process that needs input to one that does not that would be great as well.
here is the sample code and the following ruby script I used for the external program...
public static void test3() throws IOException{
String line;
Scanner scan = new Scanner(System.in);
Process process = Runtime.getRuntime ().exec ("/home/cdancy/Desktop/start.rb");
OutputStream stdin = process.getOutputStream ();
InputStream stderr = process.getErrorStream ();
InputStream stdout = process.getInputStream ();
BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
String temp = "\n";
writer.write(temp);
writer.close();
System.out.println("before loop");
while ((line = reader.readLine ()) != null) {
System.out.println ("Stdout: " + line);
String input = scan.nextLine();
input += "\n";
writer = new BufferedWriter(new OutputStreamWriter(stdin));
writer.write(input);
writer.close();
}
reader.close();
}
here is the simple ruby script i am using...
#! /usr/bin/ruby
puts "Enter a number: "
line = gets
puts "Number is " + line
puts "Enter another number: "
line = gets
puts "Second number is " + line
puts "Script is done"
again any help is appreciated.
Thanks in advance,