From: Jan B. <ja...@mo...> - 2004-03-29 22:37:28
|
Kev, What exactly is the error you get when you run this under Jetty (with DEBUG turned on)? Have you had a look at the example sh scripts used in the CGI servlet demo in Jetty? I notice that they send back at least one header before sending back the page contents. Code inspection on the CGI servlet indicates that it is expecting to see some headers. I can't see where your Perl script is sending any headers? Jan ke...@fu... wrote: > OK, I wrote a simple Java app thats proves this is a Jetty problem and not a Java/Windows/Perl bug. Complete code is below. When you run it, you'll see the correct output: > OUTPUT>64.233 > ExitValue: 0 > So the question remains, why does Jetty's CGI servlet fail? Is it perhaps that Jetty is not gobbling up the output stream properly in its own thread? > Here is an excellent article dealing with the ins and out of Runtime exec: > http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html > > > package com; > > /** > * Test perl script with inet_aton() socket call. > */ > public class CgiTest > { > public static void main(String[] argv) > { > try > { > Process proc = Runtime.getRuntime().exec("C:/perl/bin/perl.exe test.cgi"); > > // any error message? > StreamGobbler errorGobbler = new > StreamGobbler(proc.getErrorStream(), "ERROR"); > > // any output? > StreamGobbler outputGobbler = new > StreamGobbler(proc.getInputStream(), "OUTPUT"); > > // kick them off > errorGobbler.start(); > outputGobbler.start(); > > // any error??? > int exitVal = proc.waitFor(); > System.out.println("ExitValue: " + exitVal); > } > catch (Exception ex) > { > ex.printStackTrace(); > } > } > } > > package com; > > import java.io.BufferedReader; > import java.io.IOException; > import java.io.InputStream; > import java.io.InputStreamReader; > > /** > * > */ > public class StreamGobbler extends Thread > { > InputStream is; > String type; > > StreamGobbler(InputStream is, String type) > { > this.is = is; > this.type = type; > } > > public void run() > { > try > { > InputStreamReader isr = new InputStreamReader(is); > BufferedReader br = new BufferedReader(isr); > String line = null; > while ((line = br.readLine()) != null) > System.out.println(type + ">" + line); > } > catch (IOException ioe) > { > ioe.printStackTrace(); > } > } > } > > > test.cgi consists of: > > #!C:/Perl/bin/perl.exe > use CGI; > use CGI::Carp qw{warningsToBrowser fatalsToBrowser}; > use Socket; > > $host = "www.google.com"; > $hostaddr = inet_aton($host); > $ip = inet_ntoa($hostaddr); > > print "\n\n<h3>IP = " + $ip + "</H3>"; > > > > >>From: Greg Wilkins <gr...@mo...> >>Date: 2004/03/19 Fri AM 08:32:14 GMT >>To: jet...@li... >>Subject: [Jetty-support] Re: CGI problem with inet_aton() >> >> >> >>ke...@fu... wrote: >> >>> The Perl script example I wrote does not import/require any environmental variables. Perhaps this is a generic Java error in the exec command? >>> *SIGH* >>> -Kevin >> >>I would assume that to be the case, as Jetty out-of-the-can does nothing >>with such permissions. Even if it did, I do not think that those >>permissions would extend beyond the bounds of an exec. >> >>I think a simple java exec test is the thing to try now. >> >>cheers >> >> >> >>------------------------------------------------------- >>This SF.Net email is sponsored by: IBM Linux Tutorials >>Free Linux tutorial presented by Daniel Robbins, President and CEO of >>GenToo technologies. Learn everything from fundamentals to system >>administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click >>_______________________________________________ >>Jetty-support mailing list >>Jet...@li... >>https://lists.sourceforge.net/lists/listinfo/jetty-support >> > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Jetty-support mailing list > Jet...@li... > https://lists.sourceforge.net/lists/listinfo/jetty-support |