-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------

Nigel Byrnes wrote:

> -----------------------------
> Please read the FAQ!
> <http://java.apache.org/faq/>
> -----------------------------
>
> Previously, I had an application running the code that is listed below. The
> application streamed a String to a perl filter and then read it back on the
> runtime input stream. This evening when I run this code from a servlet, I
> don't appear to be getting any output from Perl. Hence my original question.
>
> If there is a problem with the code below, will the use of
> javax.servlet.ServletOutputStream and javax.servlet.ServletInputStream be of
> better use than OutputStramWriter/InputStreamWriter?
>
> Thanks
>
> Nigel
>

While I agree with other posters that using a Java regular expression matcher
is the better way to do this, I've got a likely explanation why your code below
doesn't work.  In your command, you are assuming that the "perl" executable is
on the PATH somewhere.  While this is commonly true for an application (because
you set the PATH in your logon script), it does not occur by default when you
run Apache JServ automatically (that is, started and stopped by Apache).

To solve this, you need to do one of the following things:

* Replace "perl" in the command with the absolute path
  to the PERL executable (something like "/usr/bin/perl"
  or whatever, depending on where it's installed.

* Use the "wrapper.path" variable in your jserv.properties
  file to set the PATH to be used by Apache JServ.

A second issue is that the pathname you are constructing for the filter is
relative to the current working directory.  You will need to calculate the
absolute path, because you don't know what the working directory is when you
start Apache JServ.  To avoid hard coding paths, a typical approach is to pass
the path of the directory containing your data files (the filters in your case)
as an initialization parameter to the servlet, which can then append the
filterName part.

Craig McClanahan


>
>  public String filterContent (String filterName) {
>
>   String  perlFilter = ".." + fs + "util" + fs + filterName,
>    command    = "perl " + getPath(perlFilter);
>
> try {
>    int ch = 0;
>    Process filter = r.exec(command);
>
>    BufferedWriter toFilter = new BufferedWriter (new OutputStreamWriter
> (filter.getOutputStream()));
>    toFilter.write(content, 0, content.length());
>    toFilter.close();
>
>    reset();
>
>    // Now read the output from Perl
>    BufferedReader fromFilter = new BufferedReader (new InputStreamReader
> (filter.getInputStream()));
>    while ((ch = fromFilter.read()) != -1)
>     content += (char) ch;
>    fromFilter.close();
>    filter.destroy();
>   }
>   catch (IOException e) {
>    System.out.println(e.getMessage());
>   }
>   return content;
>  }
>
> Nimret Sandhu wrote:
>
> > > Should there be any problem with servlets using java.lang.Runtime on my
> > > JServ installation? Or is the Runtime API java-application only?
> >
> > no .. there are no problems accessing the java.lang.Runtime class via
> > servlets.
> >
>
> --
> --------------------------------------------------------------
> Please read the FAQ! <http://java.apache.org/faq/>
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Archives and Other:  <http://java.apache.org/main/mail.html>
> Problems?:           [EMAIL PROTECTED]



--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to