6 个版本
0.3.0 | 2023年12月12日 |
---|---|
0.2.3 | 2023年10月31日 |
0.2.2 | 2022年4月1日 |
0.2.1 | 2021年8月12日 |
0.1.0 | 2021年5月4日 |
#256 in Unix API
27,345 下载/月
在 17 个 crate 中使用 (10 个直接使用)
19KB
284 代码行数(不包括注释)
command-fds
用于在创建子进程时传递任意文件描述符的库。
示例
use command_fds::{CommandFdExt, FdMapping};
use std::fs::File;
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.as_raw_fd(),
child_fd: 3,
},
// Map this process's stdin as FD 5 in the child process.
FdMapping {
parent_fd: 0,
child_fd: 5,
},
])
.unwrap();
// Spawn the child process.
let mut child = command.spawn().unwrap();
child.wait().unwrap();
许可证
在 Apache 许可证 2.0 版本 下授权。
贡献
如果您想为此项目做出贡献,请查看我们如何接受贡献的详细说明。
依赖
~2–10MB
~108K SLoC