Class: LCR::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/long-command-runner/container.rb

Overview

This class aims to contain the runing script.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, opts = {}) ⇒ Container

Initializer takes the command as a plain string. it imediatly launch the command

Parameters:

  • command (String)

    The command to execute.

  • opts (Hash) (defaults to: {})

    The option to pass to Open3.popen3.



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

#stderrIO (readonly)

Note:

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.

Returns:

  • (IO)


30
31
32
# File 'lib/long-command-runner/container.rb', line 30

def stderr
  @stderr
end

#stdinIO (readonly)

Note:

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.

Returns:

  • (IO)


14
15
16
# File 'lib/long-command-runner/container.rb', line 14

def stdin
  @stdin
end

#stdoutIO (readonly)

Note:

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.

Returns:

  • (IO)


22
23
24
# File 'lib/long-command-runner/container.rb', line 22

def stdout
  @stdout
end

Instance Method Details

#pidObject

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.

Returns:

  • (Boolean)


41
42
43
# File 'lib/long-command-runner/container.rb', line 41

def running?
  @wait_thr.alive?
end

#statusProcess:Status?

Get the status of the process without blocking.

Returns:

  • (Process:Status, nil)

    The exit status of the process if it is finished. if the Process isn’t finished it return nil.



49
50
51
52
53
# File 'lib/long-command-runner/container.rb', line 49

def status
  return nil if running?

  @wait_thr.value
end

#waitProcess::Status

Wait and return the process exit status. This method is blocking until the process if finished.

Returns:

  • (Process::Status)


59
60
61
# File 'lib/long-command-runner/container.rb', line 59

def wait
  @wait_thr.value
end