Struct openssh::RemoteChild

source ·
pub struct RemoteChild<'s> { /* private fields */ }
Expand description

Representation of a running or exited remote child process.

This structure is used to represent and manage remote child processes. A remote child process is created via the Command struct through Session::command, which configures the spawning process and can itself be constructed using a builder-style interface.

Calling wait (or other functions that wrap around it) will make the parent process wait until the child has actually exited before continuing.

Unlike std::process::Child, RemoteChild does implement Drop, and will terminate the local ssh process corresponding to the remote process when it goes out of scope. Note that this does not terminate the remote process. If you want to do that, you will need to kill it yourself by executing a remote command like pkill to kill it on the remote side.

As a result, RemoteChild cannot expose stdin, stdout, and stderr as fields for split-borrows like std::process::Child does. Instead, it exposes stdin, stdout, and stderr as methods. Callers can call .take() to get the same effect as a split borrow and use multiple streams concurrently. Note that for the streams to be available,Stdio::piped() should be passed to the corresponding method on Command.

NOTE that once RemoteChild is dropped, any data written to stdin will not be sent to the remote process and stdout and stderr will yield EOF immediately.

let stdin = child.stdin().take().unwrap();
let stdout = child.stdout().take().unwrap();
tokio::io::copy(&mut stdout, &mut stdin).await;

Implementations§

source§

impl<'s> RemoteChild<'s>

source

pub fn session(&self) -> &'s Session

Access the SSH session that this remote process was spawned from.

source

pub async fn disconnect(self) -> Result<()>

Disconnect from this given remote child process.

Note that disconnecting does not kill the remote process, it merely kills the local handle to that remote process.

source

pub async fn wait(self) -> Result<ExitStatus, Error>

Waits for the remote child to exit completely, returning the status that it exited with.

This function will continue to have the same return value after it has been called at least once.

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.

source

pub async fn wait_with_output(self) -> Result<Output, Error>

Simultaneously waits for the remote child to exit and collect all remaining output on the stdout/stderr handles, returning an Output instance.

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.

By default, stdin, stdout and stderr are inherited from the parent. In order to capture the output into this Result<Output> it is necessary to create new pipes between parent and child. Use stdout(Stdio::piped()) or stderr(Stdio::piped()), respectively.

source

pub fn stdin(&mut self) -> &mut Option<ChildStdin>

Access the handle for reading from the remote child’s standard input (stdin), if requested.

source

pub fn stdout(&mut self) -> &mut Option<ChildStdout>

Access the handle for reading from the remote child’s standard output (stdout), if requested.

source

pub fn stderr(&mut self) -> &mut Option<ChildStderr>

Access the handle for reading from the remote child’s standard error (stderr), if requested.

Trait Implementations§

source§

impl<'s> Debug for RemoteChild<'s>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s> !Freeze for RemoteChild<'s>

§

impl<'s> !RefUnwindSafe for RemoteChild<'s>

§

impl<'s> Send for RemoteChild<'s>

§

impl<'s> Sync for RemoteChild<'s>

§

impl<'s> Unpin for RemoteChild<'s>

§

impl<'s> !UnwindSafe for RemoteChild<'s>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more