seaver has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,

I have created a web interface that runs a perl script once the form has been submitted. The server is tomcat and the webpages are JSP.

I have written a little line in the beginning of the perl script that 'touches' a new file to indicate that it is running. Whilst running it, it puts its results into a previously created and unique directory.

This results are then in turn accessed again by the web interface.

Everything goes well except for one weird thing, when I want to run the script again, ie re-submit the form WITHIN the same session. The 'touched' file that indicates that the perl script was started is updated, so I KNOW that the perl script started to run. But there is NO OTHER output, and the script itself crashes or exits before I even can find it with 'ps ax'.

I am confused as to why it does this after the first time it is run. if I close the browser completely, and wait 60 minutes, then it will work again just fine.

I really believe it's something to do with the output streams:

open SAVEERR, ">&STDERR"; open SAVEOUT, ">&STDOUT"; $|=1; ...rest of script... close STDERR; open STDERR, ">&main::SAVEERR"; close STDOUT; open STDOUT, ">&main::SAVEOUT";
in the bean that runs the script I have this java code:
String[] cmd ={"/home/seaver/MONSTER/monster", "-i" + jobID, filePath ++ pdbFileName}; try{ Process proc = Runtime.getRuntime().exec(cmd); BufferedWriter output = new BufferedWriter(new OutputStrea +mWriter(proc.getOutputStream())); BufferedReader input = new BufferedReader(new InputStreamR +eader(proc.getInputStream())); BufferedReader error = new BufferedReader(new InputStreamR +eader(proc.getErrorStream())); output.close(); input.close(); error.close(); }catch (Throwable t){ t.printStackTrace(); }

can anyone throw any light on this?

thanks Sam

edit jeffa - s/pre/code/g

Replies are listed 'Best First'.
Re: Perl script ran from Java Bean
by perlplexer (Hermit) on Apr 17, 2003 at 20:31 UTC
    You could start by adding proper error handling to your Perl code. I see that you're not checking return values of your open()s. There could be more in the code that we don't see.

    I'd say your best bet is to figure out the exact location where the script is die()ing. Then you can start thinking about why it may be doing that.

    --perlplexer