Class: Microsandbox::ExecHandle
- Inherits:
-
Object
- Object
- Microsandbox::ExecHandle
- Includes:
- Enumerable
- Defined in:
- lib/microsandbox/exec_handle.rb
Overview
A live, streaming command execution, returned by Sandbox#exec_stream and Sandbox#shell_stream.
Iterate it (it is Enumerable) to consume ExecEvents as they arrive, or call #collect to drain it into an ExecOutput.
Instance Method Summary collapse
-
#collect ⇒ ExecOutput
Drain the stream and collect all output.
-
#each {|event| ... } ⇒ self, Enumerator
Yield each ExecEvent until the stream ends.
-
#id ⇒ String
The correlation id for this execution.
-
#initialize(native) ⇒ ExecHandle
constructor
A new instance of ExecHandle.
-
#kill ⇒ nil
Kill the running process (SIGKILL).
-
#resize(rows, cols) ⇒ nil
Resize the pseudo-terminal (only meaningful when started with tty: true).
-
#signal(sig) ⇒ nil
Send a signal (integer) to the running process.
-
#stdin ⇒ ExecStdin?
The stdin writer, or nil if stdin was not piped.
-
#wait ⇒ ExitStatus
Block until the process exits.
Constructor Details
#initialize(native) ⇒ ExecHandle
Returns a new instance of ExecHandle.
93 94 95 |
# File 'lib/microsandbox/exec_handle.rb', line 93 def initialize(native) @native = native end |
Instance Method Details
#collect ⇒ ExecOutput
Drain the stream and collect all output.
123 124 125 |
# File 'lib/microsandbox/exec_handle.rb', line 123 def collect ExecOutput.new(@native.collect) end |
#each {|event| ... } ⇒ self, Enumerator
Yield each Microsandbox::ExecEvent until the stream ends. Returns an Enumerator when called without a block.
106 107 108 109 110 111 112 113 |
# File 'lib/microsandbox/exec_handle.rb', line 106 def each return enum_for(:each) unless block_given? while (event = @native.recv) yield ExecEvent.new(event) end self end |
#id ⇒ String
Returns the correlation id for this execution.
98 99 100 |
# File 'lib/microsandbox/exec_handle.rb', line 98 def id @native.id end |
#kill ⇒ nil
Kill the running process (SIGKILL).
136 137 138 139 |
# File 'lib/microsandbox/exec_handle.rb', line 136 def kill @native.kill nil end |
#resize(rows, cols) ⇒ nil
Resize the pseudo-terminal (only meaningful when started with tty: true).
143 144 145 146 |
# File 'lib/microsandbox/exec_handle.rb', line 143 def resize(rows, cols) @native.resize(Integer(rows), Integer(cols)) nil end |
#signal(sig) ⇒ nil
Send a signal (integer) to the running process.
129 130 131 132 |
# File 'lib/microsandbox/exec_handle.rb', line 129 def signal(sig) @native.signal(Integer(sig)) nil end |
#stdin ⇒ ExecStdin?
The stdin writer, or nil if stdin was not piped. Returned only once.
150 151 152 153 154 155 |
# File 'lib/microsandbox/exec_handle.rb', line 150 def stdin return @stdin if defined?(@stdin) native_sink = @native.take_stdin @stdin = native_sink && ExecStdin.new(native_sink) end |
#wait ⇒ ExitStatus
Block until the process exits.
117 118 119 |
# File 'lib/microsandbox/exec_handle.rb', line 117 def wait ExitStatus.new(@native.wait) end |