亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 互操作性 - 打印語句未顯示在命令行中

PHP 互操作性 - 打印語句未顯示在命令行中

PHP
慕桂英3389331 2023-07-01 15:35:33
我遇到 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);


http://img1.sycdn.imooc.com//649fd790000161ce09740484.jpg

查看完整回答
反對 回復 2023-07-01
  • 1 回答
  • 0 關注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號