Re: Can Java program evoke and run a FORTRAN program directly?
Matt Humphrey wrote:
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 matth@ivizNOSPAM.com 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>