作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Perl 程序将用户输入正确格式化为 Fortran 程序的输入文件。 Fortran 程序创建一个输出文件和错误文件。 Fortran 程序是从 Perl 调用的,如:
system "/mydirectories/fortranexecutable $inputfile $outputfile $errorfile";
最佳答案
如果 Fortran 代码按顺序从已经存在的文件中读取和写入,但您想从 Perl 代码中“实时”与它通信,那么您可以使用 named pipes 来解决问题。 .它们仍然作为文件系统中的条目存在,并且可以通过给定它们的名称的 Fortran 代码像往常一样打开文件,但是从/向它们读取/写入的工作就像管道一样。
在 Perl 中,你会做这样的事情(公然复制自 this answer ):
use File::Temp qw(tempdir);
use File::Spec::Functions qw(catfile);
use POSIX qw(mkfifo);
my $dir = tempdir(CLEANUP=>1);
my $inputfifo = catfile($dir, "input");
mkfifo($inputfifo, 0700) or die "mkfifo($inputfifo) failed: $!";
my $outputfifo = catfile($dir, "output");
mkfifo($outputfifo, 0700) or die "mkfifo(output$fifo) failed: $!";
my $errorfifo = catfile($dir, "error");
mkfifo($errorfifo, 0700) or die "mkfifo($errorfifo) failed: $!";
... open the FIFOs ...
system "/mydirectories/fortranexecutable $inputfifo $outputfifo $errorfifo";
... operate with the FIFOs to communicate with the Fortran code ...
... close FIFOs and remove $dir when finished ...
关于perl - 从 Perl 调用 Fortran 程序而不保存输入/输出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11020608/
我是一名优秀的程序员,十分优秀!