首页 > 解决方案 > 从 PHP 执行 Fortran 程序

问题描述

我正在尝试通过 PHP 执行一些 fortran 程序。基本上我有一个网络表单,可以上传一个包含一些数据的文本文件,fortran 应该获取文本文件,获取数据,然后返回另一个带有结果的文本文件。例如,一个包含一些数字列表的文本文件和一个 fortran 程序应该得到它,计算并返回这些数字的平均值。

我正在运行一个 apache 服务器,想知道是否可以让 PHP 执行 fortran 程序。如果有可能,我将如何去做?

谢谢

标签: phpfortranexecutable

解决方案


您可以在 php.ini 中使用 shell_exec 命令。

<?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);

?>

推荐阅读