Skip to main content

Overview

CommandResult is a Pydantic model that encapsulates the result of executing a command on a guest VM. It provides exit code, stdout, stderr, and convenience properties for checking command success.

Model Definition

All CommandResult instances are immutable (frozen) after creation.

Fields

exit_code
int
Exit code of the executed command. A value of 0 indicates success, while non-zero values indicate errors.
stdout
str
Standard output captured from the command execution. Contains all text written to stdout during command execution.
stderr
str
Standard error captured from the command execution. Contains all text written to stderr during command execution.

Properties

ok

Whether the command succeeded (exit_code == 0).
return
bool
True if the command succeeded (exit_code is 0), False otherwise.

output

Convenience alias for stripped standard output.
return
str
The stdout with leading and trailing whitespace removed.

Usage Examples

Basic Command Execution

Checking Command Success

Handling Command Errors

Capturing Multi-line Output

Using the output Property

Conditional Execution Based on Results

Parsing Command Output

Error Handling Pattern

Working with Binary Output

Chaining Commands with Result Checks

Shell Mode Comparison

Immutability

CommandResult instances are frozen and cannot be modified:

Field Summary

Property Summary

Last modified on May 5, 2026