php - PHP 互操作性 - 打印语句未在命令行中显示
问题描述
我遇到了 PHP 没有从 Fortran 返回打印语句的问题。这个想法是 PHP 执行一个命令来编译一个 Fortran 文件然后运行它。
您被要求通过打印语句输入一个数字,问题是没有显示 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)
else
write(*,*) "Invalid number, try again" !Boo invalid input
end if
end do
end if
End Program
Subroutine calculateSequence(NumberOfTerms)
Integer :: pt1 = 0, pt2 = 1
Integer :: pt3
Call CPU_TIME(timeForSubRoutineStart)
i = NumberOfTerms
do while (i > 0)
pt3 = pt1
pt1 = pt1 + pt2
pt2 = pt3
i = i-1
write(*,*) "Point A Equals", pt1, "Point B Equals", pt2, "Calculated Next Number", pt3
write(*,*) "Current Term = ", i
write(*,*) "This program calculated this many points ", NumberOfTerms
write(*,*) "End"
end do
Call CPU_TIME(timeForSubRoutineEnd)
totalTime = timeEnd - timeBegin
write(*,*) "This program took ", totalTime, " seconds to execute"
end Subroutine calculateSequence
编辑 - 添加了关于问题@roygvib Suggested ECHO 的新图像,它现在正在返回一些打印语句
解决方案
推荐阅读
- firebase - 无效参数:在 URI 文件中未指定主机:///null
- node.js - 如何在我的响应中返回捕获的错误?(AWS Lambda 节点.js 14)
- java - Java内存缓存
- c - 三元运算符的第一个表达式中的赋值运算符如何处理?
- google-analytics - Google Analytics - 实时数据不可用于主机名过滤器
- angular - 如何测试从服务接收 Observable 的属性值
- shopify - shopify-buy SDK 无法结帐或将商品添加到购物车了
- android - 如何在 TMapView 中使用样式化地图
- docker - 在本地主机上运行 docker 容器
- javascript - Recaptcha v3 与 Jquery 选择器不兼容