I would like to run a shell script(.sh) from a Java class.
Which is the most efficient and fastest way to achieve this?
Is it better to run this script directly from Java, using groovy or is there another way?
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.
Simply use a process builder to create and execute your script:
You could also just fire out a call to
Runtime.exec():Personally I’d go with the first approach – it lets you set arguments, working directory, environment variables etc. in a much cleaner and easier way than with just an
exec()call.