Method: Aruba::Processes::SpawnProcess#start

Defined in:
lib/aruba/processes/spawn_process.rb

#start {|SpawnProcess| ... } ⇒ Object

Run the command

Yields:



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/aruba/processes/spawn_process.rb', line 144

def start
  if started?
    error_message =
      "Command \"#{commandline}\" has already been started." \
      " Please `#stop` the command first and `#start` it again." \
      " Alternatively use `#restart`."
    raise CommandAlreadyStartedError, error_message
  end

  @started = true

  @process = ProcessRunner.new(command_string.to_a)

  @stdout_file = Tempfile.new("aruba-stdout-")
  @stderr_file = Tempfile.new("aruba-stderr-")

  @stdout_file.sync = true
  @stderr_file.sync = true

  @stdout_file.set_encoding("ASCII-8BIT")
  @stderr_file.set_encoding("ASCII-8BIT")

  @exit_status = nil

  before_run

  @process.stdout = @stdout_file
  @process.stderr = @stderr_file
  @process.cwd    = @working_directory

  @process.environment = environment

  begin
    @process.start
    sleep startup_wait_time
  rescue SystemCallError => e
    raise LaunchError, "It tried to start #{commandline}. " + e.message
  end

  after_run

  yield self if block_given?
end