Struct cargo::util::process_builder::ProcessBuilder
source · pub struct ProcessBuilder { /* private fields */ }
Expand description
A builder object for an external process, similar to std::process::Command
.
Implementations
sourceimpl ProcessBuilder
impl ProcessBuilder
sourcepub fn program<T: AsRef<OsStr>>(&mut self, program: T) -> &mut ProcessBuilder
pub fn program<T: AsRef<OsStr>>(&mut self, program: T) -> &mut ProcessBuilder
(chainable) Set the executable for the process.
sourcepub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut ProcessBuilder
pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut ProcessBuilder
(chainable) Add an arg to the args list.
sourcepub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut ProcessBuilder
pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut ProcessBuilder
(chainable) Add many args to the args list.
sourcepub fn args_replace<T: AsRef<OsStr>>(
&mut self,
arguments: &[T]
) -> &mut ProcessBuilder
pub fn args_replace<T: AsRef<OsStr>>(
&mut self,
arguments: &[T]
) -> &mut ProcessBuilder
(chainable) Replace args with new args list
sourcepub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder
(chainable) Set the current working directory of the process
sourcepub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut ProcessBuilder
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut ProcessBuilder
(chainable) Set an environment variable for the process.
sourcepub fn env_remove(&mut self, key: &str) -> &mut ProcessBuilder
pub fn env_remove(&mut self, key: &str) -> &mut ProcessBuilder
(chainable) Unset an environment variable for the process.
sourcepub fn get_program(&self) -> &OsString
pub fn get_program(&self) -> &OsString
Get the executable name.
sourcepub fn get_env(&self, var: &str) -> Option<OsString>
pub fn get_env(&self, var: &str) -> Option<OsString>
Get an environment variable as the process will see it (will inherit from environment unless explicitally unset).
sourcepub fn get_envs(&self) -> &HashMap<String, Option<OsString>>
pub fn get_envs(&self) -> &HashMap<String, Option<OsString>>
Get all environment variables explicitly set or unset for the process (not inherited vars).
sourcepub fn inherit_jobserver(&mut self, jobserver: &Client) -> &mut Self
pub fn inherit_jobserver(&mut self, jobserver: &Client) -> &mut Self
Set the make
jobserver. See the jobserver crate for
more information.
sourcepub fn exec(&self) -> CargoResult<()>
pub fn exec(&self) -> CargoResult<()>
Run the process, waiting for completion, and mapping non-success exit codes to an error.
sourcepub fn exec_replace(&self) -> CargoResult<()>
pub fn exec_replace(&self) -> CargoResult<()>
Replaces the current process with the target process.
On Unix, this executes the process using the unix syscall execvp
, which will block
this process, and will only return if there is an error.
On Windows this isn’t technically possible. Instead we emulate it to the best of our ability. One aspect we fix here is that we specify a handler for the ctrl-c handler. In doing so (and by effectively ignoring it) we should emulate proxying ctrl-c handling to the application at hand, which will either terminate or handle it itself. According to microsoft’s documentation at: https://docs.microsoft.com/en-us/windows/console/ctrl-c-and-ctrl-break-signals the ctrl-c signal is sent to all processes attached to a terminal, which should include our child process. If the child terminates then we’ll reap them in Cargo pretty quickly, and if the child handles the signal then we won’t terminate (and we shouldn’t!) until the process itself later exits.
sourcepub fn exec_with_output(&self) -> CargoResult<Output>
pub fn exec_with_output(&self) -> CargoResult<Output>
Execute the process, returning the stdio output, or an error if non-zero exit status.
sourcepub fn exec_with_streaming(
&self,
on_stdout_line: &mut dyn FnMut(&str) -> CargoResult<()>,
on_stderr_line: &mut dyn FnMut(&str) -> CargoResult<()>,
print_output: bool
) -> CargoResult<Output>
pub fn exec_with_streaming(
&self,
on_stdout_line: &mut dyn FnMut(&str) -> CargoResult<()>,
on_stderr_line: &mut dyn FnMut(&str) -> CargoResult<()>,
print_output: bool
) -> CargoResult<Output>
Execute a command, passing each line of stdout and stderr to the supplied callbacks, which can mutate the string data.
If any invocations of these function return an error, it will be propagated.
Optionally, output can be passed to errors using print_output
sourcepub fn build_command(&self) -> Command
pub fn build_command(&self) -> Command
Converts ProcessBuilder into a std::process::Command
, and handles the jobserver if
present.
Trait Implementations
sourceimpl Clone for ProcessBuilder
impl Clone for ProcessBuilder
sourcefn clone(&self) -> ProcessBuilder
fn clone(&self) -> ProcessBuilder
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more