tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Kukulies <k...@gilberto.physik.RWTH-Aachen.DE>
Subject Re: OT: java programming Q
Date Wed, 10 May 2000 17:19:24 GMT
On Wed, May 10, 2000 at 05:44:34PM +0200, Viehl Clemens wrote:
> > The only thing I'm still wondering about is how I can for example
> > make the C program sending it's stdout to
> > PrintWriter out = response.getWriter(); , in other words, can 
> > I write a
> > C program cprog or bourne shell script:
> > main() { printf("<HTML>Hello World</HTML>"};
> > 
> > and exec this C program from within the servlet
> > 
>  
> > String action="cprog";
> > Runtime runner= Runtime.getRuntime();
> > runner.exec(action);
> > 
> > This doesn't seem to work. And I havn't yet found where the output 
> > goes at all.
> 
> runner.exec returns a process.
> Write:
> 
>   Runtime runtime = Runtime.getRuntime ();
>   Process process = runtime.exec (action);
> 
>   InputStream in  = process.getInputStream ();
>   InputStream err = process.getErrorStream ();
> 
> This should work.
> 

With this piece of code I'm now able to use shell scripts or whatever programs
exec'ed from within a servlet and have them output HTML to the 
servlets outputstream:

                   Runtime runner= Runtime.getRuntime();
                   String action="/usr/local/www/cgi-bin/cprog";
                   out.println("try executing..."+action);
                   try {
                        int b;
                        Process p=runner.exec(action);
                        InputStream in =p.getInputStream();
                        while((b=in.read()) >0) {   
                                out.write(b);
                        }
		   } catch (Exception e) { ...  }


Thanks to all for their comments, advice etc.

-- 
Chris Christoph P. U. Kukulies kuku@gil.physik.rwth-aachen.de

Mime
View raw message