I have master password for terminal setup and I would like to create a Java program which adds a few extra features. To do this I need to send and receive input/output from the terminal. I tried what was suggested in Java Program that runs commands with Linux Terminal but didn't have any luck. For some reason the input isn't passed in and Your master password:
is printed out if I force stop (which is were the input was supposed to be passed in). Below is my code, can anyone see what I am doing wrong?
try
{
// Send the command
Process process = new ProcessBuilder("mpw", "-u", "Name", "-t", "l", "Website").start();
String key = "somekey";
OutputStream stdOutput = process.getOutputStream();
// Send an input
stdOutput.write(key.getBytes());
// Store the input (and error) in a buffer
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// Read the output from the command:
int data;
while ((data = stdInput.read()) != -1)
System.out.write(data);
while ((data = stdError.read()) != -1)
System.out.write(data);
System.out.flush();
}
catch (IOException e) { e.printStackTrace(); }
Thanks in advance