Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- use std::io::{self};
- use std::process::Command;
- use std::process::Child;
- fn execute(children: &mut HashMap<u32, Child>, arg: &str) {
- let child = Command::new("/usr/bin/echo")
- .arg(arg)
- .spawn();
- match child {
- Ok(child) => {
- // QUESTION: this appears to work, but should be &child to avoid copying?
- // doing merely that fails claiming the lifetime expires, so how to do it correctly?
- children.insert(child.id(), child);
- }
- Err(err) => {
- eprintln!("failed to spawn: {}", err);
- }
- }
- }
- fn main() {
- let mut children: HashMap<u32, Child> = HashMap::new();
- let stdin = io::stdin();
- for line in stdin.lines() {
- let input = String::from(&line.unwrap());
- for word in input.split_whitespace() {
- execute(&mut children, word);
- }
- }
- dbg!(&children);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement