Module: Cr::Exec

Extended by:
Exec
Included in:
Cr, Exec
Defined in:
lib/cr/exec.rb,
lib/cr/exec/version.rb

Overview

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#codeObject



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, **options, &block)
  command = args.join(" ")
  if block
    IO.popen(command, options) do |pipe|
      pipe.each_line(chomp: chomp, &block)
    end
  else
    IO.popen(command, options).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

#runObject



12
13
14
15
# File 'lib/cr/exec.rb', line 12

def run(...)
  pid, status = Process.wait2(spawn(...))
  status
end

#system?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cr/exec.rb', line 43

def system?(...)
  system(...) ? true : false
end