Class: E2B::Services::CommandResult

Inherits:
Object
  • Object
show all
Defined in:
lib/e2b/services/command_handle.rb

Overview

Result of a command execution in the sandbox.

Returned by E2B::Services::CommandHandle#wait when the command finishes successfully.

Examples:

result = handle.wait
puts result.stdout
puts result.exit_code  # => 0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout: "", stderr: "", exit_code: 0, error: nil) ⇒ CommandResult

Returns a new instance of CommandResult.

Parameters:

  • stdout (String) (defaults to: "")

    Standard output

  • stderr (String) (defaults to: "")

    Standard error

  • exit_code (Integer) (defaults to: 0)

    Exit code

  • error (String, nil) (defaults to: nil)

    Error message



91
92
93
94
95
96
# File 'lib/e2b/services/command_handle.rb', line 91

def initialize(stdout: "", stderr: "", exit_code: 0, error: nil)
  @stdout = stdout
  @stderr = stderr
  @exit_code = exit_code
  @error = error
end

Instance Attribute Details

#errorString? (readonly)

Returns Error message from command execution, if any.

Returns:

  • (String, nil)

    Error message from command execution, if any



85
86
87
# File 'lib/e2b/services/command_handle.rb', line 85

def error
  @error
end

#exit_codeInteger (readonly)

Returns Exit code of the command (0 indicates success).

Returns:

  • (Integer)

    Exit code of the command (0 indicates success)



82
83
84
# File 'lib/e2b/services/command_handle.rb', line 82

def exit_code
  @exit_code
end

#stderrString (readonly)

Returns Standard error accumulated from the command.

Returns:

  • (String)

    Standard error accumulated from the command



79
80
81
# File 'lib/e2b/services/command_handle.rb', line 79

def stderr
  @stderr
end

#stdoutString (readonly)

Returns Standard output accumulated from the command.

Returns:

  • (String)

    Standard output accumulated from the command



76
77
78
# File 'lib/e2b/services/command_handle.rb', line 76

def stdout
  @stdout
end

Instance Method Details

#outputString

Combined output (stdout + stderr).

Returns:

  • (String)


108
109
110
# File 'lib/e2b/services/command_handle.rb', line 108

def output
  "#{@stdout}#{@stderr}"
end

#success?Boolean

Check if the command finished successfully.

Returns:

  • (Boolean)

    true if exit code is 0 and no error is present



101
102
103
# File 'lib/e2b/services/command_handle.rb', line 101

def success?
  @exit_code == 0 && @error.nil?
end

#to_sString Also known as: inspect

Returns:

  • (String)


113
114
115
# File 'lib/e2b/services/command_handle.rb', line 113

def to_s
  "#<#{self.class.name} exit_code=#{@exit_code} stdout=#{@stdout.bytesize}B stderr=#{@stderr.bytesize}B>"
end