bash – 将fortran程序输出到变量中
发布时间:2020-12-15 21:02:29 所属栏目:安全 来源:网络整理
导读:我有一个交互式FORTRAN程序,需要用户提供各种输入.现在,我想将此Fortran程序的输出存储到变量中,并在 shell脚本中使用此值.我试过了 var=`./test` and var=$(./test) 但在这两种情况下,它都不会提示用户输入并保持空闲状态.我该怎么办? 一段示例fortran代码
我有一个交互式FORTRAN程序,需要用户提供各种输入.现在,我想将此Fortran程序的输出存储到变量中,并在
shell脚本中使用此值.我试过了
var=`./test` and var=$(./test) 但在这两种情况下,它都不会提示用户输入并保持空闲状态.我该怎么办? test.f program test character*1 resp1,resp3 integer resp2,ans write(*,*) 'Think of a prime number less than 10' write(*,*) 'Say whether it is odd or even' write(*,*) 'Write o/e' read(*,*) resp1 if ( resp1 .EQ. 'e' ) then ans=2 else write(*,*) 'Is the number close to 4 or 8' read (*,*) resp2 if ( resp2 == 8 ) then ans=7 else write(*,*) 'Is the number greater than or less than 4' write(*,*) 'Write g or l' read (*,*) resp3 if ( resp3 .EQ. 'l' ) then ans=3 else ans=5 end if end if end if write(*,*) ans end Compiled as gfortran test.f -o test 然后我使用了这样的脚本 test.sh var=`./test` echo "The answer you are looking for is " $var 我相信我无法找到一些非常微不足道的东西.请帮我. 附:这只是一个示例代码和脚本,我的实际脚本和代码差别很大. 解决方法
Jean-Fran?oisFabre是对的.
program test character*1 resp1,resp3 integer resp2,ans write(0,*) 'Think of a prime number less than 10' write(0,*) 'Say whether it is odd or even' write(0,*) 'Write o/e' read(5,*) resp1 if ( resp1 .EQ. 'e' ) then ans=2 else write(0,*) 'Is the number close to 4 or 8' read (5,*) resp2 if ( resp2 == 8 ) then ans=7 else write(0,*) 'Is the number greater than or less than 4' write(0,*) 'Write g or l' read (5,*) resp3 if ( resp3 .EQ. 'l' ) then ans=3 else ans=5 end if end if end if write(6,*) ans end 问题是stderr(0),答案是stdin(5),结果是stdout(6) var=`./test` 之后工作得很好. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Bootstrap清除浮动的实现原理
- bootstrap + angularjs + springmvc + mybatis框架之加载lo
- angular – 如何在锚点上有条件地使用[href]或[routerLink]
- scala – scrooge-sbt-plugin的存储库是什么?
- linux – 什么是/ dev/mapper/vg_root -lv_root目录?为什
- 使用 CXF 做 webservice 简单例子
- 在vim中,您可以从命令行分割多个文件?
- 如何保存我在vim中打开的文件作为错误的用户?
- 数组 – 将数组从一个Bash脚本传递到另一个
- AngularJS 初上手体验<一>概论