1
use std::io::Write;
2
use std::process::{Command, Stdio};
3

            
4
pub struct Run {
5
    pub stdout: String,
6
    pub stderr: String,
7
}
8

            
9
60
pub fn session(units: &[&str]) -> Run {
10
60
    let mut child = Command::new(env!("CARGO_BIN_EXE_nms"))
11
60
        .arg("--no-graphics")
12
60
        .stdin(Stdio::piped())
13
60
        .stdout(Stdio::piped())
14
60
        .stderr(Stdio::piped())
15
60
        .spawn()
16
60
        .expect("spawn nms");
17
172
    let source: String = units.iter().map(|unit| format!("{unit}\n")).collect();
18
60
    child
19
60
        .stdin
20
60
        .take()
21
60
        .expect("nms stdin")
22
60
        .write_all(source.as_bytes())
23
60
        .expect("feed nms");
24
60
    let out = child.wait_with_output().expect("nms exits");
25
60
    Run {
26
60
        stdout: String::from_utf8_lossy(&out.stdout).into_owned(),
27
60
        stderr: String::from_utf8_lossy(&out.stderr).into_owned(),
28
60
    }
29
60
}