class MXC::Process
A command running in a sandbox, as returned by Sandbox#spawn.
process = MXC.sandbox.spawn("python3 -i") process.write("print(6 * 7)\n") process.close_write process.each { |chunk| print chunk.content } process.wait # => #<MXC::Result exit_code=0 ...>
Output is read in the background from the start, so the command never blocks on a full pipe, and the timeout applies whether or not anything waits.
Public Instance Methods
Source
# File lib/mxc/process.rb, line 41 def close_write @native.close_stdin nil end
Closes the command’s standard input, so it reads end of file.
Source
# File lib/mxc/process.rb, line 48 def each return enum_for(:each) unless block_given? while (chunk = @chunks.pop) yield chunk end self end
Yields each Chunk of output as it arrives, until the command closes both output streams. Returns an Enumerator without a block.
Source
# File lib/mxc/process.rb, line 58 def kill @native.kill nil end
Stops the command and everything it started.
Source
# File lib/mxc/process.rb, line 31 def pid @native.pid end
Returns the operating system process id of the sandbox.
Source
# File lib/mxc/process.rb, line 66 def wait @lock.synchronize { @result || (@result = finish) } end
Closes standard input, waits for the command to finish, and returns its Result.
Raises Error, or UnsupportedError for a host problem, when the sandbox itself could not start.
Source
# File lib/mxc/process.rb, line 36 def write(data) @native.write(data.to_s) end
Writes data to the command’s standard input and returns the number of bytes written.