I have a problem with interacting with some terminal application (in my situation it is openSSL). I have a command to send and then this application wants password and reply given password. My code doesn't work. I mean that I don't see any output from it.
For testing I've made also simple application which is waiting for two strings to type and running it from my Java code works.
Have you any suggestions?
ProcessBuilder pb = new ProcessBuilder("openssl.exe");
Process process = pb.start();
final InputStream is = process.getInputStream();
new Thread(new Runnable() {
public void run() {
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
OutputStream out = process.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write("genrsa -des3 -out ca.key 512\n");
writer.write("password\n");
writer.write("password\n");
writer.flush();
writer.close();
process.waitFor();