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
  • 5,996
  • 16
  • 49
  • 56
user3344382
  • 1,901
  • 3
  • 17
  • 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
  • 39,784
  • 16
  • 75
  • 127
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
  • 11,859
  • 5
  • 42
  • 70