sheredom/subprocess.h
Free🐜 single header process launching solution for C and C++
FreeFree tier
About sheredom/subprocess.h
subprocess.h is a single-header C/C++ library for launching and interacting with subprocesses in a cross-platform manner. It supports Linux, macOS, and Windows, and works with GCC, Clang, MSVC, and clang-cl. The library provides a simple API to create processes, write to stdin, read from stdout and stderr, wait for completion, and check return codes. It includes Unicode support on Windows and offers error codes for common failures like process not found or permission denied.
Key Features
Single header library – just #include subprocess.h
Cross-platform support: Linux, macOS, and Windows
Compiler support: GCC, Clang, MSVC, clang-cl
Launch processes with command line arguments as array
Interact with stdin, stdout, and stderr via FILE handles
Wait for process completion and retrieve return code
Unicode support on Windows (UTF-8 interpreted command line)
Error handling with subprocess_error_e codes (not found, permission denied)
Option to search user PATH for executable
Cleanup resources with subprocess_destroy
Pros & Cons
Pros
- Very easy to integrate: single header file, no build system dependency
- Clean and minimalistic API for basic process I/O
- Actively maintained with compatibility across major platforms and compilers
- Supports Unicode on Windows without extra encoding handling
- Provides clear error codes for common failure modes
Cons
- Limited to C/C++ only; not usable from other languages without binding
- No built-in support for timeouts or asynchronous process I/O
- Manual management of FILE handles and process resources required
- No high-level abstractions like process pools or pipelines
- Documentation is minimal (mainly README examples)
Best For
Running external commands or scripts from within C/C++ applicationsBuilding cross-platform build systems or task runnersImplementing test harnesses that spawn child processesCreating wrappers around CLI tools for automationDeveloping process management utilities in embedded or systems programming