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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think that you even explained the answer into your question.
When you are running external application from java either using
Runtime.exec()orProcessBuilderyou 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
sshin 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 runssh otherhostand then send user/password from java. If you need this you have to run the command via other command line utility namedexpectthat simulates terminal and is driven by script.