Ionică Bizău
Ionică Bizău

Reputation: 113385

Spawn processes in Fortran

How to start a child process in Fortran (such as executing a shell command or so)?

In Node.js, we can use either spawn or exec to start child processes:

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) {
   ...
});

Both of the examples above run ls -l (list the files and directories). How can the same thing be achieved in Fortran?

Upvotes: 1

Views: 436

Answers (1)

infixed
infixed

Reputation: 1155

This seemed like a "How do you drive in a nail with a socket wrench" type question, but I decided to try a google on it and found

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

They've been adding stuff like that to FORTRAN (in the 2008 spec), who knew?

Upvotes: 4

Related Questions