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.
90 91 92 |
# File 'lib/microsandbox/exec_handle.rb', line 90 def initialize(native) @native = native end |
Instance Method Details
#collect ⇒ ExecOutput
Drain the stream and collect all output.
120 121 122 |
# File 'lib/microsandbox/exec_handle.rb', line 120 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.
103 104 105 106 107 108 109 110 |
# File 'lib/microsandbox/exec_handle.rb', line 103 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.
95 96 97 |
# File 'lib/microsandbox/exec_handle.rb', line 95 def id @native.id end |
#kill ⇒ nil
Kill the running process (SIGKILL).
133 134 135 136 |
# File 'lib/microsandbox/exec_handle.rb', line 133 def kill @native.kill nil end |
#resize(rows, cols) ⇒ nil
Resize the pseudo-terminal (only meaningful when started with tty: true).
140 141 142 143 |
# File 'lib/microsandbox/exec_handle.rb', line 140 def resize(rows, cols) @native.resize(Integer(rows), Integer(cols)) nil end |
#signal(sig) ⇒ nil
Send a signal (integer) to the running process.
126 127 128 129 |
# File 'lib/microsandbox/exec_handle.rb', line 126 def signal(sig) @native.signal(Integer(sig)) nil end |
#stdin ⇒ ExecStdin?
The stdin writer, or nil if stdin was not piped. Returned only once.
147 148 149 150 151 152 |
# File 'lib/microsandbox/exec_handle.rb', line 147 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.
114 115 116 |
# File 'lib/microsandbox/exec_handle.rb', line 114 def wait ExitStatus.new(@native.wait) end |