Module: Cr::Exec
Overview
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #code ⇒ Object
- #each_line(*args, chomp: false, **options, &block) ⇒ Object
- #output(*args, chomp: true) ⇒ Object
- #run ⇒ Object
- #system? ⇒ Boolean
Instance Method Details
#code ⇒ Object
17 18 19 20 21 22 |
# File 'lib/cr/exec.rb', line 17 def code(...) pid, status = Process.wait2(spawn(...)) status.exitstatus rescue Errno::ENOENT 127 end |
#each_line(*args, chomp: false, **options, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cr/exec.rb', line 32 def each_line(*args, chomp: false, **, &block) command = args.join(" ") if block IO.popen(command, ) do |pipe| pipe.each_line(chomp: chomp, &block) end else IO.popen(command, ).readlines(chomp: chomp) end end |
#output(*args, chomp: true) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/cr/exec.rb', line 24 def output(*args, chomp: true) command = args.join(" ") output = `#{command}` return output.chomp if chomp output end |
#run ⇒ Object
12 13 14 15 |
# File 'lib/cr/exec.rb', line 12 def run(...) pid, status = Process.wait2(spawn(...)) status end |
#system? ⇒ Boolean
43 44 45 |
# File 'lib/cr/exec.rb', line 43 def system?(...) system(...) ? true : false end |