pub struct CommandFlow { /* private fields */ }std only.Expand description
๐ฅ๏ธ โฌก An executable flow of OS process invocations.
๐ work/process
A CommandFlow represents one or more Commands executed as a single unit.
In the current implementation, commands are arranged linearly, connecting
the stdout of each command to the stdin of the next.
Command flows are constructed programmatically (for example via cmd!)
and do not involve a shell. As a result:
- No globbing, quoting, or redirection is performed.
- Each command is spawned directly via the OS process API.
Execution is eager: all commands in the flow are spawned before waiting for completion.
See also the cmd! macro for a compact construction syntax.
Implementationsยง
Sourceยงimpl CommandFlow
impl CommandFlow
Sourcepub fn new(cmd: Command) -> Self
pub fn new(cmd: Command) -> Self
Creates a new flow with a single command.
This is equivalent to a flow of length 1, with no piping.
Sourcepub fn command_shell(line: &str) -> Result<Self, ShellWordError> โ
Available on crate feature shell only.
pub fn command_shell(line: &str) -> Result<Self, ShellWordError> โ
shell only.Creates a one-command flow from shell-like command words.
Sourcepub fn then(self, next: Command) -> Self
pub fn then(self, next: Command) -> Self
Appends a command to the flow, piping the previous command into it.
The stdout of the current command is connected to the stdin of next using an OS pipe.
This consumes the flow and returns an extended one, allowing chaining.
ยงPanics
Panics if the flow is empty. This invariant is upheld by construction.
Sourcepub fn run(self) -> IoResult<ExitStatus>
pub fn run(self) -> IoResult<ExitStatus>
Runs the flow and waits for all commands to complete.
All commands are spawned first. The method then waits for each process, returning the exit status of the last command in the flow.
Standard input, output, and error streams are inherited unless modified earlier (for example by piping or capture methods).
ยงErrors
Returns an I/O error if any command fails to spawn or wait.
Sourcepub fn stdout(self) -> IoResult<Output>
pub fn stdout(self) -> IoResult<Output>
Runs the flow and captures the standard output of the last command.
The stdout of the final command is redirected into a pipe and fully collected into a byte buffer.
All commands are spawned before any output is read.
The method waits for all commands to complete and returns
an Output containing the exit status and captured stdout.
The stderr field is empty.
ยงNotes
- Output is buffered in memory.
- Stderr is not captured.
ยงErrors
Returns an I/O error if spawning, piping, reading, or waiting fails.
Sourcepub fn output(self) -> IoResult<Output>
pub fn output(self) -> IoResult<Output>
Runs the flow and captures both stdout and stderr of the last command.
The stdout and stderr streams of the final command are merged into a single byte stream, equivalent to:
... | cmd 2>&1ยงNotes
- The relative ordering of stdout and stderr bytes is unspecified.
- Output is buffered in memory.
Returns an Output containing the exit status and merged stdout/stderr.
The merged output is stored in Output.stdout; stderr is empty.
ยงErrors
Returns an I/O error if spawning, piping, reading, or waiting fails.
Sourcepub fn stdout_with<F>(self, f: F) -> IoResult<ExitStatus>
pub fn stdout_with<F>(self, f: F) -> IoResult<ExitStatus>
Runs the flow and streams the stdout of the last command to a callback.
The provided function f is invoked incrementally with chunks of bytes
as they become available from the final commandโs standard output.
This enables streaming consumption without buffering the full output in memory.
ยงExecution model
- All commands are spawned eagerly.
- Bytes are read from the pipe in a loop.
- The callback is invoked on the reader thread.
ยงNotes
- Only stdout of the last command is streamed.
- Stderr is inherited.
Returns the exit status of the last command.
ยงErrors
Returns an I/O error if spawning, piping, reading, or waiting fails.
Trait Implementationsยง
Auto Trait Implementationsยง
impl !RefUnwindSafe for CommandFlow
impl !UnwindSafe for CommandFlow
impl Freeze for CommandFlow
impl Send for CommandFlow
impl Sync for CommandFlow
impl Unpin for CommandFlow
impl UnsafeUnpin for CommandFlow
Blanket Implementationsยง
Sourceยงimpl<T> AnyExt for T
impl<T> AnyExt for T
Sourceยงfn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Sourceยงfn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Sourceยงfn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> ByteSized for T
impl<T> ByteSized for T
Sourceยงconst BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Sourceยงfn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Sourceยงfn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Sourceยงimpl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Sourceยงconst NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Sourceยงfn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Sourceยงfn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Sourceยงfn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSourceยงfn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSourceยงfn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงunsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงunsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงfn mem_as_bytes(&self) -> &[u8] โ
fn mem_as_bytes(&self) -> &[u8] โ
unsafe_slice only.