in scala I run
val result = Process("kinit user@SOMETHING.COM")
which then expects an input
Password for user@SOMETHING.COM:
is there a way for me to enter it from code?
In order to work with input and output from a process you need to open it so that you can get the STDIN
and STDOUT
streams. A good example can be found in the questionJava Process with Input/Output Stream. This is still pretty painful, if you are trying to automate some code that requires input on prompts.
In unix this is traditionally handled with the Expect library, and fortunately, there is a java port of it on github as Expect4J. Using Expect4J, you still start the process the same way and get it's input and output streams, but then feed those to Expect4J and program your interaction from there:
val expect = new Expect4j(process.getInputStream(), process.getOutputStream())
expect.expect("Password for user@SOMETHING.COM:")
expect.send(password)