我遇到 PHP 未从 Fortran 返回打印语句的问题。这个想法是 PHP 执行一个命令来编译 Fortran 文件然后运行它。系统要求您通过 print 语句输入一个数字,问题是没有显示在 CMD 上,但程序按预期工作 - 当我输入“不正确”的数字时,它会等待我输入“正确”的数字,然后完成执行。如何让命令行打印 Fortran 文件中嵌套的语句?PHP 脚本$<?php// This is a script to test interoperability between Fortran and PHP$ExecutionStringOne = "gfortran C:\Users\****\Desktop\Programs\Fortran_Programs\FibSequence.f95 -o C:\Users\****\Desktop\Programs\Fortran_Programs\FibSequenceTest";$ExecutionStringTwo = "C:\Users\*****\Desktop\Programs\Fortran_Programs\FibSequenceTest.exe";exec ($ExecutionStringOne);exec ($ExecutionStringTwo);?>Fortran 代码:! This program will calculate the first 7 numbers in the Fibonacci sequence with user input as well as error checking Program FibSequence implicit none ! Defining our global variables Integer :: acceptValue, n_terms ! Accept Value: 0, 1 - This tracks whether input is correct (0 False, 1 True) , N_terms: Number of terms real :: timeForSubRoutineStart, timeForSubRoutineEnd, totalTime ! Tracks execution time of subroutine write(*,*) "Please input an amount of terms to calculate sequentially to - This number can be between 1 and 7" read *, n_terms if (n_terms > 0 .AND. n_terms <= 7) then acceptValue = 1 ! This is true therefore run program (This isnt really needed but for consistency) Call calculateSequence(n_terms) else acceptValue = 0 ! This is false therefore run the read again and keep doing so until the output is correct do while ( acceptValue == 0 ) write(*,*) "Invalid number please enter one within the given range - Range ( 1 - 7 )" read *, n_terms if (n_terms > 0 .AND. n_terms <= 7) then acceptValue = 1 !Yay correct input Call calculateSequence(n_terms)编辑 - 添加了有关问题@roygvib 建议的 ECHO 的新图像,它现在返回一些打印语句
1 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
在用户的帮助下@roygvib我找到了问题的解决方案。
PHP 执行文件和命令的几种不同方式 - 问题集中使用的一种方式是exec()
执行程序而不返回任何输出。
另一方面,存在它将System()
启动给定的命令和可执行文件,并返回程序执行生命周期内存在的任何输出。
TLDR:使用System
而不是Exec
解决我遇到的问题。
system ($ExecutionStringOne); system ($ExecutionStringTwo);
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消