Class: Net::SSH::Shell::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/shell/process.rb

Direct Known Subclasses

Subshell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager, command, properties, callback) ⇒ Process

Returns a new instance of Process.



10
11
12
13
14
15
16
17
18
19
# File 'lib/net/ssh/shell/process.rb', line 10

def initialize(manager, command, properties, callback)
  @command = command
  @manager = manager
  @callback = callback
  @properties = properties
  @on_output = nil
  @on_error_output = nil
  @on_finish = nil
  @state = :new
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



6
7
8
# File 'lib/net/ssh/shell/process.rb', line 6

def callback
  @callback
end

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/net/ssh/shell/process.rb', line 4

def command
  @command
end

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



7
8
9
# File 'lib/net/ssh/shell/process.rb', line 7

def exit_status
  @exit_status
end

#managerObject (readonly)

Returns the value of attribute manager.



5
6
7
# File 'lib/net/ssh/shell/process.rb', line 5

def manager
  @manager
end

#propertiesObject (readonly)

Returns the value of attribute properties.



8
9
10
# File 'lib/net/ssh/shell/process.rb', line 8

def properties
  @properties
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/net/ssh/shell/process.rb', line 3

def state
  @state
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/net/ssh/shell/process.rb', line 21

def [](key)
  @properties[key]
end

#[]=(key, value) ⇒ Object



25
26
27
# File 'lib/net/ssh/shell/process.rb', line 25

def []=(key, value)
  @properties[key] = value
end

#busy?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/net/ssh/shell/process.rb', line 67

def busy?
  starting? || running?
end

#finished?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/net/ssh/shell/process.rb', line 63

def finished?
  state == :finished
end

#on_error_output(&callback) ⇒ Object



80
81
82
# File 'lib/net/ssh/shell/process.rb', line 80

def on_error_output(&callback)
  @on_error_output = callback
end

#on_finish(&callback) ⇒ Object



84
85
86
# File 'lib/net/ssh/shell/process.rb', line 84

def on_finish(&callback)
  @on_finish = callback
end

#on_output(&callback) ⇒ Object



76
77
78
# File 'lib/net/ssh/shell/process.rb', line 76

def on_output(&callback)
  @on_output = callback
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/net/ssh/shell/process.rb', line 33

def run
  if state == :new
    state = :starting
    manager.open do
      state = :running
      manager.channel.on_data(&method(:on_stdout))
      manager.channel.on_extended_data(&method(:on_stderr))
      manager.channel.on_close(&method(:on_close))

      callback.call(self) if callback

      cmd = command.dup
      cmd << ";" if cmd !~ /[;&]$/
      cmd << " DONTEVERUSETHIS=$?; echo #{manager.separator} $DONTEVERUSETHIS; echo \"exit $DONTEVERUSETHIS\"|sh"

      send_data(cmd + "\n")
    end
  end

  self
end

#running?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/net/ssh/shell/process.rb', line 59

def running?
  state == :running
end

#send_data(data) ⇒ Object



29
30
31
# File 'lib/net/ssh/shell/process.rb', line 29

def send_data(data)
  manager.channel.send_data(data)
end

#starting?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/net/ssh/shell/process.rb', line 55

def starting?
  state == :starting
end

#wait!Object



71
72
73
74
# File 'lib/net/ssh/shell/process.rb', line 71

def wait!
  manager.session.loop { busy? }
  self
end