Module: Rya::CoreExtensions::Process

Includes:
Time
Defined in:
lib/rya/core_extensions.rb

Instance Method Summary collapse

Methods included from Time

#date_and_time, #time_it

Instance Method Details

#run_and_time_it!(title = "", cmd = "", logger = Rya::AbortIf::logger, &b) ⇒ Object

Run a command and time it as well!

Examples:


Process.extend Rya::CoreExtensions::Process
Time.extend Rya::CoreExtensions::Time

Process.run_and_time_it! "Saying hello",
                         %Q{echo "hello world"}

Process.run_and_time_it! "This will raise SystemExit",
                         "ls arstoeiarntoairnt"


149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rya/core_extensions.rb', line 149

def run_and_time_it! title = "",
                     cmd = "",
                     logger = Rya::AbortIf::logger,
                     &b

  Rya::AbortIf.logger.debug { "Running: #{cmd}" }

  time_it title, logger do
    run_it! cmd, &b
  end
end

#run_it(*a, &b) ⇒ Object

Runs a command and outputs stdout and stderr



113
114
115
116
117
118
119
120
# File 'lib/rya/core_extensions.rb', line 113

def run_it *a, &b
  exit_status, stdout, stderr = systemu *a, &b

  puts stdout unless stdout.empty?
  STDERR.puts stderr unless stderr.empty?

  exit_status
end

#run_it!(*a, &b) ⇒ Object

Like run_it() but will raise Rya::AbortIf::Exit on non-zero exit status.



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rya/core_extensions.rb', line 123

def run_it! *a, &b
  exit_status = self.run_it *a, &b

  # Sometimes, exited? is not true and there will be no exit
  # status. Success should catch all failures.
  Rya::AbortIf.abort_unless exit_status.success?,
                            "Command failed with status " \
                                "'#{exit_status.to_s}' " \
                                "when running '#{a.inspect}', " \
                                "'#{b.inspect}'"

  exit_status
end