Skip to main content

Shell

Struct Shell 

Source
pub struct Shell<'a> { /* private fields */ }
Expand description

A reusable WinRM shell session.

Created via WinrmClient::open_shell. The shell persists across multiple command executions, avoiding the overhead of creating and deleting a shell per command.

The shell is automatically closed when dropped (best-effort). For reliable cleanup, call close explicitly.

Implementations§

Source§

impl<'a> Shell<'a>

Source

pub fn resource_uri(&self) -> &str

The resource URI this shell was created with.

Source

pub async fn run_command( &self, command: &str, args: &[&str], ) -> Result<CommandOutput, WinrmError>

Execute a command in this shell.

Runs the command, polls for output until completion or timeout, and returns the collected stdout, stderr, and exit code.

Source

pub async fn run_command_with_cancel( &self, command: &str, args: &[&str], cancel: CancellationToken, ) -> Result<CommandOutput, WinrmError>

Execute a command with cancellation support.

Like run_command, but can be cancelled via a CancellationToken. When cancelled, a Ctrl+C signal is sent to the running command and WinrmError::Cancelled is returned.

Source

pub async fn run_powershell( &self, script: &str, ) -> Result<CommandOutput, WinrmError>

Execute a PowerShell script in this shell.

The script is encoded as UTF-16LE base64 and executed via powershell.exe -EncodedCommand.

Source

pub async fn run_powershell_with_cancel( &self, script: &str, cancel: CancellationToken, ) -> Result<CommandOutput, WinrmError>

Execute a PowerShell script with cancellation support.

Like run_powershell, but can be cancelled via a CancellationToken.

Source

pub async fn send_input( &self, command_id: &str, data: &[u8], end_of_stream: bool, ) -> Result<(), WinrmError>

Send input data (stdin) to a running command.

The command_id identifies which command receives the input. Set end_of_stream to true to signal EOF on stdin.

Source

pub async fn signal_ctrl_c(&self, command_id: &str) -> Result<(), WinrmError>

Send Ctrl+C signal to a running command.

Requests graceful interruption of the command identified by command_id.

Source

pub async fn start_command_with_id( &self, command: &str, args: &[&str], command_id: &str, ) -> Result<String, WinrmError>

Start a command and return the command ID for manual polling.

Use with receive_next and signal_ctrl_c for fine-grained control over long-running commands.

§Example
let cmd_id = shell.start_command("ping", &["-t", "10.0.0.1"]).await?;
loop {
    let chunk = shell.receive_next(&cmd_id).await?;
    print!("{}", String::from_utf8_lossy(&chunk.stdout));
    if chunk.done { break; }
}

Like start_command but lets the caller specify the CommandId that the server should assign to the command. Used by PSRP where the pipeline UUID must match the CommandId.

Source

pub async fn start_command( &self, command: &str, args: &[&str], ) -> Result<String, WinrmError>

Source

pub async fn receive_next( &self, command_id: &str, ) -> Result<ReceiveOutput, WinrmError>

Poll for the next output chunk from a running command.

Returns a single ReceiveOutput representing one poll cycle. Callers should accumulate stdout/stderr and stop when done is true.

Source

pub fn shell_id(&self) -> &str

Get the shell ID.

Source

pub async fn close(self) -> Result<(), WinrmError>

Explicitly close the shell, releasing server-side resources.

Source

pub async fn disconnect(self) -> Result<String, WinrmError>

Disconnect from the shell while leaving it alive on the server.

Returns the shell_id so the caller can later reconnect via WinrmClient::reconnect_shell. The local Shell value is consumed; calling close on a disconnected shell is unnecessary because the server-side resources are still owned by the runspace.

Trait Implementations§

Source§

impl Drop for Shell<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Shell<'a>

§

impl<'a> !RefUnwindSafe for Shell<'a>

§

impl<'a> Send for Shell<'a>

§

impl<'a> Sync for Shell<'a>

§

impl<'a> Unpin for Shell<'a>

§

impl<'a> UnsafeUnpin for Shell<'a>

§

impl<'a> !UnwindSafe for Shell<'a>

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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