aspose file tools*
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
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: 39551
    
  27
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 - updated with new look and Ping home screen widget
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Run .sh file using java
 
Similar Threads
Problem with running a shell script from the JSP
Creating subdomain using java
dynamically loading a class file from a jar file
Execute "echo $BASHPID" in Linux using Java
Runtime getRuntime() exec(cmd[]) - How does this work?