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 15:26:31 GMT
On Wed, May 10, 2000 at 08:33:10AM -0600, M Butcher wrote:
> So the servlet executes a C program? And the C program doesn't behaive as
> expected? That is probably because none of the CGI environment variables are set
> for the program. You are executing it outside of the normal CGI context, so any
> particular information that _was_ being sent to the CGI (in the form of env. vars
> or arguments) is now being sent to the servlet engine. If you really want to make
> this method work, you need to have the java set all of the correct environment
> variables for the C program.

Yes, I understand this so. I could pick up
the CGI environment in the java code and then pass them as
commandline arguments or something to the C programs.

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.

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

> 
> Christoph Kukulies wrote:
> 
> > The more I'm playing with servlets the more I like it and the more
> > I'm moving the CGI program parts to servlets.
> >
> > But for efficiency reasons there's a lot I'd still prefer to be done with CGI
> > programs (C programs).
> >
> > One thing I found when I tried to concentrate several buttons in
> > an ACTION=/servlets/Some which should dispatch dependent on the button
> > pressed.
> >
> > As long as I stay in Java, everything is fine.
> >
> > Now I want to exec my CGI-C program and the whole CGI context gets lost,
> > even the outputstream.
> >
> > I'm using java.lang.Runtime exec() for this.
> >
> > Is there a way to let the exec'ed process inherit the environment?
> > Don't know how this could be achieved but writing everything
> > in Java would be too much for the moment.
> >
> > E.g:
> >
> > public void doGet (HttpServletRequest request,
> >                    HttpServletResponse response)
> >         throws ServletException, IOException
> >         {
> >          String type =  request.getParameter("type");
> >          if(type.compareTo("Reportausgabe")==0){
> >                   out.println("Reportausgabe");
> >                   try {
> >                    out.println("executing...");
> >                    action="/usr/local/www/cgi-bin/test.sh";
> >                    runner.exec(action);
> >                   } catch(Exception e) {
> >                       out.println("EXEC error");
> >                       out.flush();
> >                       e.printStackTrace();
> >                     }
> >                   return;
> >             }
> >
> > You can also email me directly if this pollutes the list.
> >
> > --
> > Chris Christoph P. U. Kukulies kuku@gil.physik.rwth-aachen.de

Mime
View raw message