diff options
Diffstat (limited to 'src/process/mod.rs')
| -rw-r--r-- | src/process/mod.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/process/mod.rs b/src/process/mod.rs index 0538eb8c62..e469ce7b58 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -19,6 +19,7 @@ pub struct OpenVpnCommand { openvpn_bin: OsString, config: Option<PathBuf>, remotes: Vec<RemoteAddr>, + forward_standard_streams: bool, } impl OpenVpnCommand { @@ -29,6 +30,7 @@ impl OpenVpnCommand { openvpn_bin: OsString::from(openvpn_bin.as_ref()), config: None, remotes: vec![], + forward_standard_streams: true, } } @@ -45,6 +47,12 @@ impl OpenVpnCommand { Ok(self) } + /// Invoke this to not create stdout and stderr streams for the subprocess + pub fn discard_standard_streams(&mut self) -> &mut Self { + self.forward_standard_streams = false; + self + } + /// Executes the OpenVPN process as a child process, returning a handle to it. pub fn spawn(&self) -> io::Result<Child> { let mut command = self.create_command(); @@ -56,11 +64,19 @@ impl OpenVpnCommand { let mut command = Command::new(&self.openvpn_bin); command.env_clear() .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); + .stdout(self.get_std_streams_forward_policy()) + .stderr(self.get_std_streams_forward_policy()); command } + fn get_std_streams_forward_policy(&self) -> Stdio { + if self.forward_standard_streams { + Stdio::piped() + } else { + Stdio::null() + } + } + /// Returns all arguments that the subprocess would be spawned with. pub fn get_arguments(&self) -> Vec<OsString> { let mut args = vec![]; |
