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>
impl<'a> Shell<'a>
Sourcepub fn resource_uri(&self) -> &str
pub fn resource_uri(&self) -> &str
The resource URI this shell was created with.
Sourcepub async fn run_command(
&self,
command: &str,
args: &[&str],
) -> Result<CommandOutput, WinrmError>
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.
Sourcepub async fn run_command_with_cancel(
&self,
command: &str,
args: &[&str],
cancel: CancellationToken,
) -> Result<CommandOutput, WinrmError>
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.
Sourcepub async fn run_powershell(
&self,
script: &str,
) -> Result<CommandOutput, WinrmError>
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.
Sourcepub async fn run_powershell_with_cancel(
&self,
script: &str,
cancel: CancellationToken,
) -> Result<CommandOutput, WinrmError>
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.
Sourcepub async fn send_input(
&self,
command_id: &str,
data: &[u8],
end_of_stream: bool,
) -> Result<(), WinrmError>
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.
Sourcepub async fn signal_ctrl_c(&self, command_id: &str) -> Result<(), WinrmError>
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.
Sourcepub async fn start_command_with_id(
&self,
command: &str,
args: &[&str],
command_id: &str,
) -> Result<String, WinrmError>
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.
pub async fn start_command( &self, command: &str, args: &[&str], ) -> Result<String, WinrmError>
Sourcepub async fn receive_next(
&self,
command_id: &str,
) -> Result<ReceiveOutput, WinrmError>
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.
Sourcepub async fn close(self) -> Result<(), WinrmError>
pub async fn close(self) -> Result<(), WinrmError>
Explicitly close the shell, releasing server-side resources.
Sourcepub async fn disconnect(self) -> Result<String, WinrmError>
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.