2016-05-16 49 views
1

如何在Fortran中启动子进程(比如执行shell命令等)?Fortran中的生成进程

在Node.js的,我们可以使用spawnexec启动子进程:

var proc = require("child_process").spawn("ls", ["-l"]); 
proc.stdout.on("data", function (chunk) { 
    console.log(chunk); 
}); 

// or 

var proc = require("child_process").exec("ls -l"], function (err, stdout, stderr) { 
    ... 
}); 

以上运行ls -l的例子(列出的文件和目录)两种。 Fortran中如何实现同样的功能?

回答

5

这似乎是一个类型的问题:“你怎么在用套筒扳手钉子驱动”,但我还是决定试试就可以了谷歌和发现

https://gcc.gnu.org/onlinedocs/gfortran/EXECUTE_005fCOMMAND_005fLINE.html

 program test_exec 
     integer :: i 

     call execute_command_line ("external_prog.exe", exitstat=i) 
     print *, "Exit status of external_prog.exe was ", i 

     call execute_command_line ("reindex_files.exe", wait=.false.) 
     print *, "Now reindexing files in the background" 

     end program test_exec 

他们已经一直在向FORTRAN(2008规格)添加这样的东西,谁知道?

+0

是否可以将命令参数作为不同的字符串发送?像一个'spawn'等价物。 –

+0

@IonicăBizău'execute_command_line'的命令参数只需要是一个(默认)字符(标量)。在这些例子中,它们是字符文字,但您可以更广泛地使用变量或表达式。 – francescalus

+3

*谁知道?*很多人,这不是保密的。 –