use tokio::process::{Child, ChildStderr, ChildStdin, ChildStdout};
pub struct ContainerProcess {
pub child: Child,
pub stdin: ChildStdin,
pub stdout: ChildStdout,
pub stderr: ChildStderr,
}
impl ContainerProcess {
#[must_use]
pub fn from_child(mut child: Child) -> Self {
let stdin = child
.stdin
.take()
.expect("ContainerProcess: child stdin not piped");
let stdout = child
.stdout
.take()
.expect("ContainerProcess: child stdout not piped");
let stderr = child
.stderr
.take()
.expect("ContainerProcess: child stderr not piped");
ContainerProcess {
child,
stdin,
stdout,
stderr,
}
}
#[must_use]
pub fn id(&self) -> Option<u32> {
self.child.id()
}
pub fn kill_now(&mut self) {
let _ = self.child.start_kill();
}
pub async fn kill_and_wait(&mut self) {
let _ = self.child.start_kill();
let _ = self.child.wait().await;
}
}