0

I want to run another Process from my Java Code and to communicate with it; I mean that the main program will call another program and will give her parameters.

Another words: the second program is running and asking for parameters and the main program should read the output of the second program and according to the output the main program should give her the values. I don't know how to write this code. Thank you so much.

the main program:

ProcessBuilder builder = new ProcessBuilder("password.jar", "Aharon");
builder.redirectErrorStream(true);
Process p = builder.start();
InputStream i = p.getInputStream();
OutputStream o = p.getOutputStream();
BufferedReader br = new BufferedReader(new
    InputStreamReader(i));
BufferedWriter bw = new BufferedWriter(new
    OutputStreamWriter(o));
bw.write("aharon");
bw.flush();
System.out.println(br.readLine());
String sudo = "am326294642";
bw.write("aharon");
bw.flush();
int x;
System.out.println(br.readLine());
while ((x = i.read()) != -1)
  System.out.print((char) x);
o.write(sudo.getBytes());
while ((x = i.read()) != -1)
  System.out.print((char) x);

the second program that should be running:

Scanner in = new Scanner(System.in);
System.out.println("insert your password");
while (!in.next().equals("aharon"))
  System.out.println("wrong!!");
System.out.println("you passed !!! !!! !");
Iwo Kucharski
  • 3,609
  • 3
  • 46
  • 64
viper-zero
  • 61
  • 1
  • 1
  • 9

0 Answers0