[jboss-user] [Tomcat, HTTPD, Servlets & JSP] - Re: how to call unix shell script from web app?
ragavgomatam
do-not-reply at jboss.com
Fri Jan 11 15:27:26 EST 2008
Code is as below :-
import java.io.*;
|
| /** Demonstrate how to run an external program. **/
| public class MyServlet implements HttpServlet{
|
| /** From the main run an servlet . **/
| public doGet( request,response) {
| try {
| Runtime rt = Runtime.getRuntime (); // step 1
|
| Process process = rt.exec ("/call/some/shell"); // step 2
|
| InputStreamReader reader = // step 3
| new InputStreamReader ( process.getInputStream () );
|
| BufferedReader buf_reader =
| new BufferedReader ( reader ); // step 4.
|
| String line;
| while ((line = buf_reader.readLine ()) != null)
| System.out.println (line);
|
| }
| catch (IOException e) {
| System.out.println (e);
| }
| }
| } // servlet end
Make sure you grab the Process & flush the err stream, input tsream & out put stream...Other wise due to insufficient length of err buffers in OS this would hang
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119242#4119242
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119242
More information about the jboss-user
mailing list