php - 从 PHP 执行 Fortran 程序
问题描述
我正在尝试通过 PHP 执行一些 fortran 程序。基本上我有一个网络表单,可以上传一个包含一些数据的文本文件,fortran 应该获取文本文件,获取数据,然后返回另一个带有结果的文本文件。例如,一个包含一些数字列表的文本文件和一个 fortran 程序应该得到它,计算并返回这些数字的平均值。
我正在运行一个 apache 服务器,想知道是否可以让 PHP 执行 fortran 程序。如果有可能,我将如何去做?
谢谢
解决方案
您可以在 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);
?>
推荐阅读
- regex - 正则表达式:更改以字符开头的行的一部分
- c# - 从 RowDetailsTemplate 中的 DataGrid 无法访问 SelectedItem
- c# - 如何创建在 Xamarin.iOS 可视化设计器中工作的 C# 枚举属性?
- javascript - 如何在动画中间添加文字?
- haskell - 将一种类型约束为另一种类型的模式
- python - 如何将 Dask 数据帧作为输入传递给 dask-ml 模型?
- python - 如何检查用户是否输入了有效值?如果输入正确,我如何将此值附加到列表中?
- java - 获取多个图像 url firebase 存储的列表
- ubuntu - GPU 英伟达不可用
- javascript - D3 Choropleth 地图 + 悬停工具提示 + 浏览器放置问题