Can Java program evoke and run a FORTRAN program directly?

S

Shawn

Hi,

I have a Java program. In order to use an existing FORTRAN program for
doing some computation, I hope I can evoke and run the FORTRAN program
from my Java program.

Somebody has told me that Java has to call a C program, which calls the
FORTRAN program. I am wondering if there is some better ways to do it.

Thank you very much.
 
M

Matt Humphrey

Shawn said:
Hi,

I have a Java program. In order to use an existing FORTRAN program for
doing some computation, I hope I can evoke and run the FORTRAN program
from my Java program.

Somebody has told me that Java has to call a C program, which calls the
FORTRAN program. I am wondering if there is some better ways to do it.

Java can invoke the OS which will in turn launch the FORTRAN program. You
can connect to the input, output and error streams of the program also, if
you want. Look for Runtime.exec () and a new helper called ProcessBuilder.
There are some gotchas, but you can find sample code, etc by searching the
web or this newsgroup.

Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
S

Shawn

Matt said:
Java can invoke the OS which will in turn launch the FORTRAN program. You
can connect to the input, output and error streams of the program also, if
you want. Look for Runtime.exec () and a new helper called ProcessBuilder.
There are some gotchas, but you can find sample code, etc by searching the
web or this newsgroup.

Matt Humphrey (e-mail address removed) http://www.iviz.com/

Thank you. I have got it running, shown below. I will improve it by
using ProcessBuilder later.

<JAVA>
public class DoRuntime {
public static void main(String args[]) throws IOException {

System.out.println("========JAVA program is going to run a FORTRAN
program========");

String cmd = "myscript"; //it contains several commands,
including one start FORTRAN
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmd);
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;

System.out.printf("Output of running %s is:", cmd);

while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("=======JAVA program has finished running a
FORTRAN program=========");

}
}
</JAVA>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top