0

I am trying to execute some fortran program through PHP. Basically I have a webform that upload a text file with some data in it, the fortran is supposed to take the text file, get data, and return another text file with results. e.g. a text file with list of some numbers and a fortran program should get it, calculate and return an average of those numbers.

I am running an apache server, and wondering if it is possible to make PHP execute the fortran program. If it is possible, how would I go about doing it?

thanks

Roman
  • 183
  • 3
  • 16
  • Please describe how does your current code look like and what did you try so far. Did you try any approach that didn't work so far? There should not be any difference between a program written in Fortran and any other executable. No difference at all. Did you try things like https://stackoverflow.com/questions/12251634/how-to-run-abc-exe-using-php and other related questions and answers here? Or read http://php.net/manual/en/function.exec.php ? I have never used PHP but if these are not the right things, then please explain why not. – Vladimir F Героям слава May 26 '18 at 18:26

1 Answers1

2

You can use shell_exec command in php.

<?php

// text file path which is uploaded by web form
$firstFile_path  = '/path/to/firstTextfile.txt'); 

// text file path which is created by fortran program
$secondFile_path = '/path/to/secondTextfile.txt'); 

//send the filepath to your fortran program and wait for the process to finish
// send first file path as argument to the fortran program
shell_exec("fortranprogram ".$firstFile_path); 

// read the second file's content
$secondFile_content = file_get_contents($secondFile_path);

?>
Meskan
  • 79
  • 4