Introduction

June 9, 2026 ยท View on GitHub

Subprocess.f
Spawning processes seamlessly
A crossplatform library to create, wait and redirect child processes.


API

Introduction

About the Project

This project aims at providing an easy and comprehensive API to spawn child processes in Fortran.
The development of this repo is linked to the discussion on the Fortran discourse about the Stdlib system interaction API

  • fpm
  • ifort
  • gfortran

Installation

Requirements

To build that library you need

  • a Fortran 2008 compliant compiler, or better, a Fortran 2018 compliant compiler.

The following compilers are tested on the default branch of subprocess.f:

NameVersionPlatformArchitecture
GCC Fortran (MinGW)14Windows 10x86_64
Intel oneAPI classic2021.5Windows 10x86_64
Intel oneAPI classic2021.13Windows 10x86_64
  • a preprocessor. The units tests of subprocess.f use quite some preprocessor macros. It is known to work both with intel fpp and cpp.
    Unit test rely on the the files assertion.inc and app.inc.

Get the code

git clone https://github.com/davidpfister/subprocess.f
cd subprocess.f

Build with fpm

The repo is compatible with fpm projects. It can be build using fpm

fpm build

Building with ifort requires to specify the compiler name (gfortran by default)

fpm build --compiler ifort

Alternatively, the compiler can be set using fpm environment variables.

set FPM_FC=ifort

Besides the build command, several commands are also available:

@prettify
system codee format ./src
system fortitude check ./src --fix
option run --list

@clean
option clean --all

@rebuild
system rmdir /s /q build
option build --flag '-ffree-line-length-none'

@build
option build --flag '-ffree-line-length-none'

@test
options test --flag '-ffree-line-length-none'

@doc
system cd ./.dox & doxygen ./Doxyfile.in & cd ..
system powershell ./tools/Fix-Doxygen.ps1 -Path "./docs"
option run --list

The toml files contains the settings to the cpp preprocessor are specified in the file.

[preprocess]
cpp.suffixes = ["F90", "f90"]
cpp.macros = ["_FPM, _WIN32"]

The _FPM macro is used to differentiate the build when compiling with fpm or Visual Studio. This is mostly present to adapt the hard coded paths that differs in both cases. The _WIN32 macro is used only on Windows system. It should be removed otherwise.

Build with Visual Studio 2019

The project was originally developed on Windows with Visual Studio 2019. The repo contains the solution file (subprocess.f.sln) to get you started with Visual Studio 2019.

Quick Start

The easiest way to invoke a subprocess is to call the run subroutine.

type(process) :: p

p = process('gfortran')
call p%run('hello_world.f90 -o hello_world')

The library is written in both functional and oop style meaning that most subroutine can be invoked both as as classical subroutine or attached procedures. For instance, the previous example would write as follows:

type(process) :: p

p = process('gfortran')
call run(p, 'hello_world.f90', '-o hello_world')

The process can also run asynchronously by invoking the runasync procedure.

type(process) :: p

p = process('gfortran')
call runasync(p, 'hello_world.f90', '-o hello_world')
!...
call wait(p)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. So, thank you for considering contributing to benchmark.f. Please review and follow these guidelines to make the contribution process simple and effective for all involved. In return, the developers will help address your problem, evaluate changes, and guide you through your pull requests.

By contributing to benchmark.f, you certify that you own or are allowed to share the content of your contribution under the same license.

License

Distributed under the MIT License.

Contributors Forks Stargazers Issues MIT License