Start process in Java which has password prompt

112 Views Asked by At

I want to start a process that asks for a password. The password should be provided automatically. I tried:

Process process = processBuilder.start();
Thread.sleep(10000);
OutputStream os = process.getOutputStream();
PrintWriter writer = new PrintWriter(os);
writer.write(new String(password) + "\n");

But the password is apparently not written to the process. The process instead waits forever until it is killed.

How can I answer password prompts from within Java?

0

There are 0 best solutions below