Module: ProcessExecuter
- Defined in:
- lib/process_executer.rb,
lib/process_executer/status.rb,
lib/process_executer/command.rb,
lib/process_executer/options.rb,
lib/process_executer/version.rb,
lib/process_executer/command/errors.rb,
lib/process_executer/command/result.rb,
lib/process_executer/command/runner.rb,
lib/process_executer/monitored_pipe.rb
Overview
rubocop:disable Layout/LineLength
Defined Under Namespace
Modules: Command Classes: MonitoredPipe, Options, Status
Constant Summary collapse
- VERSION =
The current Gem version
'1.3.0'
Class Method Summary collapse
-
.run(*command, logger: Logger.new(nil), **options_hash) ⇒ ProcessExecuter::Command::Result
Execute the given command as a subprocess, blocking until it finishes.
-
.spawn(*command, **options_hash) ⇒ Process::Status
Execute the given command as a subprocess and return the exit status.
Class Method Details
.run(*command, logger: Logger.new(nil), **options_hash) ⇒ ProcessExecuter::Command::Result
Execute the given command as a subprocess, blocking until it finishes
Returns a result object which includes the process's status and output.
Supports the same features as Process.spawn. In addition, it:
- Blocks until the command exits
- Captures stdout and stderr to a buffer or file
- Optionally kills the command if it exceeds a timeout
This method takes two forms:
The command is executed via a shell when the command is given as a single string:
ProcessExecuter.run([env, ] command_line, options = {}) ->ProcessExecuter::Command::ResultThe command is executed directly (bypassing the shell) when the command and it arguments are given as an array of strings:
ProcessExecuter.run([env, ] exe_path, *args, options = {}) ->ProcessExecuter::Command::Result
Optional argument env is a hash that affects ENV for the new process; see
Execution
Environment.
Argument options is a hash of options for the new process. See the options listed below.
256 257 258 |
# File 'lib/process_executer.rb', line 256 def self.run(*command, logger: Logger.new(nil), **) ProcessExecuter::Command::Runner.new(logger).call(*command, **) end |
.spawn(*command, **options_hash) ⇒ Process::Status
Execute the given command as a subprocess and return the exit status
This is a convenience method that calls Process.spawn and blocks until the command terminates.
The command will be sent the SIGKILL signal if it does not terminate within the specified timeout.
67 68 69 70 71 |
# File 'lib/process_executer.rb', line 67 def self.spawn(*command, **) = ProcessExecuter::Options.new(**) pid = Process.spawn(*command, **.) wait_for_process(pid, ) end |