• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# command-fds
2
3[![crates.io page](https://img.shields.io/crates/v/command-fds.svg)](https://crates.io/crates/command-fds)
4[![docs.rs page](https://docs.rs/command-fds/badge.svg)](https://docs.rs/command-fds)
5
6A library for passing arbitrary file descriptors when spawning child processes.
7
8## Example
9
10```rust
11use command_fds::{CommandFdExt, FdMapping};
12use std::fs::File;
13use std::os::unix::io::AsRawFd;
14use std::process::Command;
15
16// Open a file.
17let file = File::open("Cargo.toml").unwrap();
18
19// Prepare to run `ls -l /proc/self/fd` with some FDs mapped.
20let mut command = Command::new("ls");
21command.arg("-l").arg("/proc/self/fd");
22command
23    .fd_mappings(vec![
24        // Map `file` as FD 3 in the child process.
25        FdMapping {
26            parent_fd: file.as_raw_fd(),
27            child_fd: 3,
28        },
29        // Map this process's stdin as FD 5 in the child process.
30        FdMapping {
31            parent_fd: 0,
32            child_fd: 5,
33        },
34    ])
35    .unwrap();
36
37// Spawn the child process.
38let mut child = command.spawn().unwrap();
39child.wait().unwrap();
40```
41
42## License
43
44Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
45
46## Contributing
47
48If you want to contribute to the project, see details of
49[how we accept contributions](CONTRIBUTING.md).
50