Module: ShellCommand
- Defined in:
- lib/shell_command.rb,
lib/shell_command/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.2.6"
Class Method Summary collapse
-
.run(*args) {|command| ... } ⇒ ShellCommand::Command
Returns a Command.
-
.run!(*args) ⇒ ShellCommand::Command
Returns a Command.
Class Method Details
.run(*args) {|command| ... } ⇒ ShellCommand::Command
Returns a Command
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/shell_command.rb', line 45 def run *args if args.empty? raise ArgumentError, 'Wrong number of arguments (0 for 1+)' end pid, stdin, stdout, stderr = Open4.open4(*args) _, status = Process.wait2(pid) command = Command.new(status, stdout.read, stderr.read) [stdin, stdout, stderr].map(&:close) if block_given? yield command else command end end |
.run!(*args) ⇒ ShellCommand::Command
Returns a Command
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/shell_command.rb', line 73 def run! *args command = run(*args) if command.success? command else raise ShellCommand::Exception, "The command '#{args.join(' ')}' has failed." end end |