Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to join java with the fortran progam

Status
Not open for further replies.

udayshri

Programmer
Feb 4, 2008
1
US

I have made a program in fortran(addition of two numbers) and want to interface it with java page and accept numbers from java page and process them in fortran program and display output on java page.. is it possible if yes i should i go about it..
 
Let me get this straight. You want to start a java program, call a fortran program with some arguments, have the results sent back to the java program, and have the java program output the results. Yes thats possible. Java can execute external commands.

Code:
StringBuffer strOutput = new StringBuffer("");
StringBuffer strError = new StringBuffer("");
String sTemp = null;
Process process = Runtime.getRuntime().exec(
     "myprog.exe  arg1 arg2");
   BufferedReader stdOutput = new BufferedReader(
     new InputStreamReader(process.getInputStream()));

   BufferedReader stdError = new BufferedReader(new InputStreamReader(
     process.getErrorStream()));


   while ((sTemp = stdOutput.readLine()) != null) {
    strOutput.append("\n").append(sTemp);
   }

   while ((sTemp = stdError.readLine()) != null) {
    strError.append("\n").append(sTemp);
   }

   returnValue = process.waitFor();
Whatever your executable outputs should be found in stdOutput.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top