How do I make sure that file handle for every `Child` process is released after every iteration?

前端 未结 1 866
谎友^
谎友^ 2021-01-23 10:35

I have the following program taken from the Rust docs for std::process::Command. It stops working after some iterations.

use std::process::Command;
use std::pro         


        
1条回答
  •  醉话见心
    2021-01-23 11:17

    If you read the paragraph immediately after the one you have quoted:

    Calling wait (or other functions that wrap around it) will make the parent process wait until the child has actually exited before continuing.

    In order to call wait, you need to not move stdout out of Child:

    let echo_out = echo_child.stdout.take().expect("failed to open 'echo' stdout");
    
    // ...
    
    echo_child.wait().expect("Couldn't wait for echo child");
    

    See also:

    • Kill child process while waiting for it

    0 讨论(0)
提交回复
热议问题