#child-process #sub-processes #fd #command

command-fds

A library for passing arbitrary file descriptors when spawning child processes

8 releases

Uses new Rust 2024

0.3.2 Jun 30, 2025
0.3.1 May 8, 2025
0.3.0 Dec 12, 2023
0.2.3 Oct 31, 2023
0.1.0 May 4, 2021

#86 in Unix APIs

Download history 18493/week @ 2025-11-11 26468/week @ 2025-11-18 14506/week @ 2025-11-25 23912/week @ 2025-12-02 15202/week @ 2025-12-09 16000/week @ 2025-12-16 6435/week @ 2025-12-23 9011/week @ 2025-12-30 25235/week @ 2026-01-06 27295/week @ 2026-01-13 21417/week @ 2026-01-20 19308/week @ 2026-01-27 23830/week @ 2026-02-03 25453/week @ 2026-02-10 28085/week @ 2026-02-17 30107/week @ 2026-02-24

110,707 downloads per month
Used in 97 crates (16 directly)

Apache-2.0

19KB
289 lines

command-fds

crates.io page docs.rs page

A library for passing arbitrary file descriptors when spawning child processes.

Example

use command_fds::{CommandFdExt, FdMapping};
use std::fs::File;
use std::io::stdin;
use std::os::fd::AsFd;
use std::os::unix::io::AsRawFd;
use std::process::Command;

// Open a file.
let file = File::open("Cargo.toml").unwrap();

// Prepare to run `ls -l /proc/self/fd` with some FDs mapped.
let mut command = Command::new("ls");
command.arg("-l").arg("/proc/self/fd");
command
    .fd_mappings(vec![
        // Map `file` as FD 3 in the child process.
        FdMapping {
            parent_fd: file.into(),
            child_fd: 3,
        },
        // Map this process's stdin as FD 5 in the child process.
        FdMapping {
            parent_fd: stdin().as_fd().try_clone_to_owned().unwrap(),
            child_fd: 5,
        },
    ])
    .unwrap();

// Spawn the child process.
let mut child = command.spawn().unwrap();
child.wait().unwrap();

License

Licensed under the Apache License, Version 2.0.

Contributing

If you want to contribute to the project, see details of how we accept contributions.

Dependencies

~1.8–5MB
~95K SLoC