• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run .sh file using java

 
Manpreet Patil
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

i want to reload apache trrough my java application on opensuse server.My .sh file placed on the path "/usr/share/tomcat6/ ". I am using following code but the output printed on tomcat log is " null "

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("sh apacheReload.sh");
process.waitFor();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
System.out.println("><><>apache restart<><><>"+br.readLine());

where apacheReload.sh is my bash file that contains:-
#! /bin/bash
/etc/init.d/apache2 reload

But when i try to reload the apache through" sh apacheReload.sh" on console it works fine.

Regards,
Manpreet
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by reading this article.
Also, you should use absolute paths to all involved files instead of relative paths like "sh" and "apacheReload.sh".
 
Manpreet Patil
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried with the absolute path like this

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("sh /usr/share/tomcat6/apacheReload.sh");
process.waitFor();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
System.out.println("><><>apache restart<><><>"+br.readLine());



but still i am facing same problem.........
 
Volodymyr Krasnikov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

have you tried the way of tomcat restarting as it tomcat-manager does ? tomcat ships with ant task that does redeployment well. and invoking ant task from java code looks better than running sh manually. plus it will gives you crossplatfom-compatibility.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic