Can I use Runtime to achieve the same? If so what are the pros/cons
I have to invoke a shell script from java.
Thanks in advance.
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.
You can use
Runtime.exec()to execute a shell script from Java. Of course this will make it less cross-platform and harder to maintain. If you want to wait for the shell script to finish you need to use the Process object returned byexec()and callwaitFor(). You can also get thestdin/out/errwhich is very useful. You might also want to explicitly call the correct shell e.g.exec("sh script.sh").