diff options
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 977db28..5e978d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,15 @@ use anyhow::bail; -use std::fs; -use std::io::Write; +use std::fs::{self, File}; +use std::io::{self, Write}; +use std::os::fd::AsFd; use std::process::Command; use std::thread; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; +fn null() -> anyhow::Result<File> { + Ok(File::open("/dev/null")?) +} + fn start() -> anyhow::Result<()> { let mut stdout = StandardStream::stdout(ColorChoice::Always); @@ -22,13 +27,20 @@ fn start() -> anyhow::Result<()> { continue; } - match Command::new(service.path()).spawn() { + let mut cmd = Command::new(service.path()); + cmd.stderr(null()?).stdin(null()?).stdout(null()?); + + match cmd.spawn() { Ok(_) => { stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?; writeln!(&mut stdout, "[ OK ] Starting {}", service_name)?; stdout.reset()?; stdout.flush()?; + + cmd.stderr(io::stderr().as_fd().try_clone_to_owned()?); + cmd.stdin(io::stdin().as_fd().try_clone_to_owned()?); + cmd.stdout(io::stdout().as_fd().try_clone_to_owned()?); } Err(e) => { stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?; |