diff options
author | yuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef> | 2025-07-08 07:12:59 +0000 |
---|---|---|
committer | yuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef> | 2025-07-08 07:12:59 +0000 |
commit | 141e546e1d7a8385817b3edb46bd91b502563cd9 (patch) | |
tree | e215d8e4d4c79fee4b94e527cef8522b27ba5cec /src/model.rs | |
parent | 8f05a437d80a243e504b4fb5d26b53bbd7de9c47 (diff) | |
download | salaryman-141e546e1d7a8385817b3edb46bd91b502563cd9.tar.gz salaryman-141e546e1d7a8385817b3edb46bd91b502563cd9.tar.bz2 salaryman-141e546e1d7a8385817b3edb46bd91b502563cd9.zip |
working proof of concept -- minecraft
git-svn-id: svn+ssh://diminuette.aengel.lesbianunix.dev/salaryman/trunk@9 b9215c17-b818-4693-b096-d1e41a411fef
Diffstat (limited to 'src/model.rs')
-rw-r--r-- | src/model.rs | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/model.rs b/src/model.rs index 8f4416b..60960e3 100644 --- a/src/model.rs +++ b/src/model.rs @@ -61,8 +61,8 @@ impl ServiceConf { pub struct Service { conf: ServiceConf, proc: Option<Arc<Mutex<Child>>>, - stdout: Option<Arc<Mutex<Receiver<String>>>>, - stderr: Option<Arc<Mutex<Receiver<String>>>>, + pub stdout: Option<Arc<Mutex<Receiver<String>>>>, + pub stderr: Option<Arc<Mutex<Receiver<String>>>>, } impl Default for Service { fn default() -> Self { @@ -109,23 +109,17 @@ impl Service { ))); } let cmd = &self.conf.command; - let args = if let Some(a) = &self.conf.args { - a.split_whitespace() - } else { - "".split_whitespace() + let mut proc = Command::new(cmd); + proc.stdin(Stdio::piped()); + proc.stdout(Stdio::piped()); + proc.stderr(Stdio::piped()); + if let Some(a) = &self.conf.args { + proc.args(a.split_whitespace()); }; - let cwd = if let Some(c) = &self.conf.directory { - c - } else { - &PathBuf::from("/") + if let Some(c) = &self.conf.directory { + proc.current_dir(c); }; - let child = Command::new(cmd) - .args(args) - .current_dir(cwd) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn()?; + let child = proc.spawn()?; self.proc = Some(Arc::new(Mutex::new(child))); Ok(()) } @@ -217,7 +211,7 @@ impl Service { spawn(async move { let mut br = BufReader::new(stderr).lines(); while let Ok(Some(line)) = br.next_line().await { - println!("ERR :: {} :: {}", &sname, &line); + eprintln!("{} :: {}", &sname, &line); if let Err(_) = tx.send(line).await { return; }; @@ -247,6 +241,7 @@ impl Service { ))); }; stdin.write(&buf.as_bytes()).await?; + stdin.flush().await?; Ok(()) } else { Err(Box::new(std::io::Error::new( |