Possible Duplicate:
Redirect stdin and stdout in Java
I know how to execute shell commands in Java but how to do it so my application can write to its input and read from its output.
Possible Duplicate:
Redirect stdin and stdout in Java
I know how to execute shell commands in Java but how to do it so my application can write to its input and read from its output.
I think that you even explained the answer into your question.
When you are running external application from java either using Runtime.exec()
or ProcessBuilder
you can access standard output and standard input streams. User input stream to read what external application writes and output stream to send commands to external application.
But be careful. Some applications will not get your commands sent from java. For example command ssh
in Unix system is designed to avoid its usage by non-human user (e.g. other application). It require to be executed from terminal for security reasons, so you cannot for example run ssh otherhost
and then send user/password from java. If you need this you have to run the command via other command line utility named expect
that simulates terminal and is driven by script.