Solved

Program hang when using Runtime.exec() unders Linux platform

Posted on 2004-04-19
3
339 Views
Last Modified: 2013-11-08
Hello,

I tried to execute a FORTRAN program by using Runtime.exec() under Linux platform. I am using Java Tomcat 1.4.1.29.
However, the FORTRAN application hang forever, which usally takes about 2 minutes to finish.

I have no problem to run it under console based stand alone application.

The codes is as follows:

                /* make a shell script*/
                BufferedWriter bw2=new BufferedWriter(new FileWriter(currentDir+"/pentran.script"));
                bw2.write("#!/bin/sh"+ "\n");
                bw2.write("cd "+currentDir+"/"+"\n");
                bw2.write("echo sample.f90 "+" | "+" /opt/tomcat/pentran/pentran" );
                bw2.close();

               /*create a process*/
                Runtime rt = Runtime.getRuntime();
               
               /*chmod permission*/
                Process changeMode = rt.exec( "chmod 755 " + currentDir + "/pentran.script" );

                Process pr = rt.exec(currentDir+"/pentran.script");

Does anyone have any ideas?

Best Regards,
Peng
0
Comment
Question by:penglu
3 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 10868001
I know very little in this area, but can I suggest you try this

put diagnostics between each main area, so you can identify where exactly the delay is, then tackle that


// DIAG1 - DISPLAY "About to create Buffer" and also show  date/time
               /* make a shell script*/
                BufferedWriter bw2=new BufferedWriter(new FileWriter(currentDir+"/pentran.script"));

// DIAG2 - DISPLAY "About to create file" and also show  date/time

                bw2.write("#!/bin/sh"+ "\n");
                bw2.write("cd "+currentDir+"/"+"\n");
                bw2.write("echo sample.f90 "+" | "+" /opt/tomcat/pentran/pentran" );
                bw2.close();

// DIAG3 - DISPLAY "About to create process" and also show  date/time
               /*create a process*/
                Runtime rt = Runtime.getRuntime();
               
// DIAG4 - DISPLAY "About to change perms of script" and also show  date/time
               /*chmod permission*/
                Process changeMode = rt.exec( "chmod 755 " + currentDir + "/pentran.script" );

// DIAG5 - DISPLAY "About to run script" and also show  date/time

                Process pr = rt.exec(currentDir+"/pentran.script");

// DIAG6 - DISPLAY "end" and also show  date/time
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question