• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Run .sh file using java

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.........
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic