Class: LCR::Container
- Inherits:
-
Object
- Object
- LCR::Container
- Defined in:
- lib/long-command-runner/container.rb
Overview
This class aims to contain the runing script.
Instance Attribute Summary collapse
-
#stderr ⇒ IO
readonly
Get the standard error IO of the process.
-
#stdin ⇒ IO
readonly
Get the standard input IO of the process.
-
#stdout ⇒ IO
readonly
Get the standard output IO of the process.
Instance Method Summary collapse
-
#initialize(command, opts = {}) ⇒ Container
constructor
Initializer takes the command as a plain string.
-
#pid ⇒ Object
Return the pid of the process.
-
#running? ⇒ Boolean
Is the last launched command is still running.
-
#status ⇒ Process:Status?
Get the status of the process without blocking.
-
#wait ⇒ Process::Status
Wait and return the process exit status.
Constructor Details
#initialize(command, opts = {}) ⇒ Container
Initializer takes the command as a plain string. it imediatly launch the command
36 37 38 |
# File 'lib/long-command-runner/container.rb', line 36 def initialize(command, opts = {}) @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(command, opts) end |
Instance Attribute Details
#stderr ⇒ IO (readonly)
Be aware that it may be closed by the process (on exit), or by you. We don’t monitor those states here.
Get the standard error IO of the process.
30 31 32 |
# File 'lib/long-command-runner/container.rb', line 30 def stderr @stderr end |
#stdin ⇒ IO (readonly)
Be aware that it may be closed by the process (on exit), or by you. We don’t monitor those states here.
Get the standard input IO of the process.
14 15 16 |
# File 'lib/long-command-runner/container.rb', line 14 def stdin @stdin end |
#stdout ⇒ IO (readonly)
Be aware that it may be closed by the process (on exit), or by you. We don’t monitor those states here.
Get the standard output IO of the process.
22 23 24 |
# File 'lib/long-command-runner/container.rb', line 22 def stdout @stdout end |
Instance Method Details
#pid ⇒ Object
Return the pid of the process
64 65 66 |
# File 'lib/long-command-runner/container.rb', line 64 def pid @wait_thr.pid end |
#running? ⇒ Boolean
Is the last launched command is still running.
41 42 43 |
# File 'lib/long-command-runner/container.rb', line 41 def running? @wait_thr.alive? end |
#status ⇒ Process:Status?
Get the status of the process without blocking.
49 50 51 52 53 |
# File 'lib/long-command-runner/container.rb', line 49 def status return nil if running? @wait_thr.value end |
#wait ⇒ Process::Status
Wait and return the process exit status. This method is blocking until the process if finished.
59 60 61 |
# File 'lib/long-command-runner/container.rb', line 59 def wait @wait_thr.value end |