Sha256: bc078e5ff4462a369b7befab22b566147ed5987a6c53eabffc045d441146ee61
Contents?: true
Size: 1.09 KB
Versions: 21
Compression:
Stored size: 1.09 KB
Contents
module EY module Backup module Spawner extend Forwardable extend self CHUNK_SIZE = 4096 def_delegator EY::Backup, :logger def spawn(command, stdout = nil, stdin = nil, stderr = logger.stderr) ioify(stdout, stdin, stderr) do |o, i, e| ios = {:stderr => e} ios[:stdout] = o if o ios[:stdin] = i if i result = Open4.spawn([command], ios) end end def run(command) unless runs?(command) raise "Failed to run #{command.inspect}" end end def runs?(command) pid, *_ = Open4.popen4(command) pid, status = Process::waitpid2(pid) status.success? end def ioify(stdout, stdin, stderr, &block) if String === stdin File.open(stdin, 'r') do |f| ioify(stdout, f, stderr, &block) end elsif String === stdout File.open(stdout, 'w') do |f| ioify(f, stdin, stderr, &block) end else yield stdout, stdin, stderr end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems