pub struct Builder { /* private fields */ }
Expand description
Process factory, which can be used in order to configure the properties of a process being created.
Methods can be chained on it in order to configure it.
Implementations§
source§impl Builder
impl Builder
sourcepub fn new() -> Self
pub fn new() -> Self
Generates the base configuration for spawning a thread, from which configuration methods can be chained.
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
procspawn::init();
let mut builder = procspawn::Builder::new();
builder.stdout(Stdio::piped());
let mut handle = builder.spawn((1, 2), |(a, b)| {
println!("{:?} {:?}", a, b);
});
let mut s = String::new();
handle.stdout().unwrap().read_to_string(&mut s).unwrap();
assert_eq!(s, "1 2\n");
}
sourcepub fn env<K, V>(&mut self, key: K, val: V) -> &mut Selfwhere
K: AsRef<OsStr>,
V: AsRef<OsStr>,
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Selfwhere K: AsRef<OsStr>, V: AsRef<OsStr>,
Set an environment variable in the spawned process.
Equivalent to Command::env
sourcepub fn envs<I, K, V>(&mut self, vars: I) -> &mut Selfwhere
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Selfwhere I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,
Set environment variables in the spawned process.
Equivalent to Command::envs
sourcepub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self
Removes an environment variable in the spawned process.
Equivalent to Command::env_remove
sourcepub fn env_clear(&mut self) -> &mut Self
pub fn env_clear(&mut self) -> &mut Self
Clears all environment variables in the spawned process.
Equivalent to Command::env_clear
sourcepub fn uid(&mut self, id: u32) -> &mut Self
pub fn uid(&mut self, id: u32) -> &mut Self
Sets the child process’s user ID. This translates to a
setuid
call in the child process. Failure in the setuid
call will cause the spawn to fail.
Unix-specific extension only available on unix.
Equivalent to std::os::unix::process::CommandExt::uid
sourcepub fn gid(&mut self, id: u32) -> &mut Self
pub fn gid(&mut self, id: u32) -> &mut Self
Similar to uid
, but sets the group ID of the child process. This has
the same semantics as the uid
field.
Unix-specific extension only available on unix.
Equivalent to std::os::unix::process::CommandExt::gid
sourcepub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Selfwhere
F: FnMut() -> Result<()> + Send + Sync + 'static,
pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Selfwhere F: FnMut() -> Result<()> + Send + Sync + 'static,
Schedules a closure to be run just before the exec
function is
invoked.
Safety
This method is inherently unsafe. See the notes of the unix command ext for more information.
Equivalent to std::os::unix::process::CommandExt::pre_exec
sourcepub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Captures the stdin
of the spawned process, allowing you to manually
send data via JoinHandle::stdin
sourcepub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Captures the stdout
of the spawned process, allowing you to manually
receive data via JoinHandle::stdout
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
procspawn::init();
let mut builder = procspawn::Builder::new();
builder.stdout(Stdio::piped());
let mut handle = builder.spawn((1, 2), |(a, b)| {
println!("{:?} {:?}", a, b);
});
let mut s = String::new();
handle.stdout().unwrap().read_to_string(&mut s).unwrap();
assert_eq!(s, "1 2\n");
}
sourcepub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Captures the stderr
of the spawned process, allowing you to manually
receive data via JoinHandle::stderr
sourcepub fn spawn<A: Serialize + DeserializeOwned, R: Serialize + DeserializeOwned>(
&mut self,
args: A,
func: fn(_: A) -> R
) -> JoinHandle<R>
pub fn spawn<A: Serialize + DeserializeOwned, R: Serialize + DeserializeOwned>( &mut self, args: A, func: fn(_: A) -> R ) -> JoinHandle<R>
Spawns the process.
Examples found in repository?
4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
procspawn::init();
let mut builder = procspawn::Builder::new();
builder.stdout(Stdio::piped());
let mut handle = builder.spawn((1, 2), |(a, b)| {
println!("{:?} {:?}", a, b);
});
let mut s = String::new();
handle.stdout().unwrap().read_to_string(&mut s).unwrap();
assert_eq!(s, "1 2\n");
}