module Scripto::RunCommands
Public Instance Methods
run(command, args = nil)
click to toggle source
Run an external command. Raise Error
if something goes wrong. The command will be echoed if verbose?.
Usage is similar to Kernel#system. If args
is nil, command
will be passed to the shell. If args
are included, the command
and args
will be run directly without the shell.
# File lib/scripto/run_commands.rb, line 16 def run(command, args = nil) cmd = CommandLine.new(command, args) vputs(cmd) cmd.run end
run_capture(command, args = nil)
click to toggle source
Run a command and capture the output like backticks. See run
for details.
# File lib/scripto/run_commands.rb, line 24 def run_capture(command, args = nil) CommandLine.new(command, args).capture end
run_fails?(command, args = nil)
click to toggle source
Returns true if the command fails. See run
for details.
# File lib/scripto/run_commands.rb, line 44 def run_fails?(command, args = nil) !run_succeeds?(command, args) end
run_quietly(command, args = nil)
click to toggle source
Run a command and suppress output by redirecting to /dev/null. See run
for details.
# File lib/scripto/run_commands.rb, line 30 def run_quietly(command, args = nil) cmd = CommandLine.new(command, args) run("#{cmd} > /dev/null 2> /dev/null") end
run_succeeds?(command, args = nil)
click to toggle source
Returns true if the command succeeds. See run
for details.
# File lib/scripto/run_commands.rb, line 36 def run_succeeds?(command, args = nil) run_quietly(command, args) true rescue Error false end
shellescape(str)
click to toggle source
Escape str if necessary. Useful for passing arguments to a shell.
# File lib/scripto/run_commands.rb, line 49 def shellescape(str) Shellwords.escape(str) end