0

I want to run bash file from java, i am using play framework. any idea how to do that??

is this code enough:

new ProcessBuilder("pathToYourShellScript").start();
user3687679
  • 359
  • 2
  • 16

1 Answers1

1

Possible duplicate of How to run Unix shell script from Java code? (don't have the reputation to put that in a comment, sorry).

In a nutshell - your line of code will work and the shell script will run by just doing that (tested on a SUSE Linux box).

However, if you want to do anything with the output or to know that it has completed, you'll have to add more code to check its state (check out the Process.waitFor() API) or to capture its output in Java (e.g. by capturing Standard out in a BufferedReader) - check Process.getInputStream() API.

Community
  • 1
  • 1
J Richard Snape
  • 20,116
  • 5
  • 51
  • 79