This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Run .sh file using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Run .sh file using java " Watch "Run .sh file using java " New topic
Author

Run .sh file using java

Manpreet Patil
Greenhorn

Joined: Oct 18, 2009
Posts: 18
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
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
Start by reading this article.
Also, you should use absolute paths to all involved files instead of relative paths like "sh" and "apacheReload.sh".


Ping & DNS - my free Android networking tools app
Manpreet Patil
Greenhorn

Joined: Oct 18, 2009
Posts: 18
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

Joined: Sep 17, 2009
Posts: 3
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.
 
Consider Paul's rocket mass heater.
 
subject: Run .sh file using java