Can Java program evoke and run a FORTRAN program directly?

Discussion in 'Java' started by Shawn, Dec 6, 2006.

  1. Shawn

    Shawn Guest

    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.
    Shawn, Dec 6, 2006
    #1
    1. Advertising

  2. "Shawn" <> wrote in message
    news:el6vbd$q9a$...
    > 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 http://www.iviz.com/
    Matt Humphrey, Dec 6, 2006
    #2
    1. Advertising

  3. Shawn

    Shawn Guest

    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 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>
    Shawn, Dec 6, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    1
    Views:
    336
    Steve C. Orr [MVP, MCSD]
    Feb 19, 2005
  2. SamX

    run Fortran from python

    SamX, Dec 15, 2003, in forum: Python
    Replies:
    3
    Views:
    635
    Fernando Perez
    Dec 15, 2003
  3. Shawn
    Replies:
    3
    Views:
    1,143
    Simon Brooke
    Oct 4, 2006
  4. Luna Moon
    Replies:
    9
    Views:
    608
    Guest
    Sep 4, 2007
  5. deadpickle
    Replies:
    1
    Views:
    978
    Jens Thoms Toerring
    Nov 7, 2010
Loading...

Share This Page