Solved

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

Posted on 2004-04-19
3
333 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now