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 16:20:51 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 ();

Yes, I read in the java book meanwhile a bit and found that Process class.

   Should I then use something like

    while(in.available() > 0) {
       in.read(byte[] b);
       out.write(b);
    }
Or how is the usual technique in Java to read from a stream file until
EOF is encountered?
> 
> This should work.
> 
> > > > But for efficiency reasons there's a lot I'd still prefer 
> > > > to be done with CGI
> > > > programs (C programs).
> 
> But i believe you will get a really bad performance using CGI within
> Servlets.
> Servlets are the replacement for such things and are more performant because
> you
> don't need to create a Operating System process as you have with CGIs. But

process creation is cheap in unix.  I have to run a couple of unix
utilities in the scripts which ic impossible to rebuild all in Java.
(like context diffs, sed, sort and all that)

> i'm not sure about this, because i know only servlets. But they are Java
> Threads who are present prompt after their first initialization. 
> Java isn't too slow when you don't have a gui. Try a fast JVM, that would
> improve speed more than mixing C and Java.

I cannot believe that. C 4 times faster than C++ 2 times faster than java.
(C 8 times faster than Java).  And even if that doesn't apply to every
situation, the argument that I cannot rewrite the power of unix
in a few hundred lines of java. That would make my project months later.

> Just my 2 cent.
> 
> Regards
> 
> Clemens Viehl
> 
> 
> --------------------------------------------------------------------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org

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

Mime
View raw message