i want to run a bash script with java ee / servlets .
I want it embedded in a web application , using tomcat 7 in a linux os.
i want to run a bash script with java ee / servlets . I
Share
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.
Get the path to the file once the application is deployed with:
String scriptPath = getServletContext().getRealPath("/script.sh");Run the script with the ProcessBuilder class:
new ProcessBuilder("/bin/sh", scriptPath).start();Note that the step 2 may fail if you servlet container doesn’t extract the content of the war file. In this case you’ll have to put the script as a resource available on the classpath, copy its content into a temporary file, and run the script there.