0

Does anyone know if it is possible to call a shell script from within Java program and also pass an argument to that shell script from the for loop of that java class? In my shell script I am setting MySQL system variables to different values to see if those values affect the performance of the database application. I could have set those values through JDBC, but as I am working with MySQL, it is not possible to restart the database from JDBC, after each query execution.

Kara
  • 6,115
  • 16
  • 50
  • 57
user3344382
  • 1,941
  • 4
  • 18
  • 17

2 Answers2

0

Yes it is possible. For something like this you would probably be better off just using a batch file or something to do it though.

If you really do need to use java try:

How to run Unix shell script from Java code?

Community
  • 1
  • 1
Tim B
  • 40,716
  • 16
  • 83
  • 128
0

Runtime.exec() is what you are looking for.

Runtime.getRuntime().exec("theScript.sh param1 param2);

..modulo exception handling.

You may want to look into Apache Commons

Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72