Sha256: c51aa133ac430a98eb466b3645dcea4ec46bbcfe91c255965bdd8d8dfc9c03cb
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
module Vimpack module Utils module Process include Io class Results attr_accessor :process, :message def initialize(process, message=nil) self.process = process self.message = message end end def run_process!(cmd) child = ::ChildProcess.build(cmd) child.io.stdout = ::Tempfile.new('child-out') child.io.stderr = ::Tempfile.new('child-err') child.start child Results.new(child) end def wait_for_child(child, timeout=240) child.process.poll_for_exit(timeout.to_f) child.process.stop unless child.process.exited? child.process.io.stdout.close child.process.io.stderr.close child.process.io.stdout.open child.process.io.stderr.open child.message = child.process.io.stdout.read child.message << " " child.message << child.process.io.stderr.read child end def run_process_and_wait!(cmd, dir=nil) child = nil within_dir(dir) do child = run_process!(cmd) end child = wait_for_child(child) end def run_process_or_die!(cmd, dir=nil, err_msg=nil) child = run_process_and_wait!(cmd, dir) child.message << err_msg if err_msg exit_with_error!("child process died:\n#{child.message}") unless child.process.exit_code == 0 child end def within_dir(dir=nil, &block) orig_path = Dir.pwd dir = dir.nil? ? orig_path : dir.to_s ::Dir.chdir(dir) block.call ::Dir.chdir(orig_path) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vimpack-0.0.4 | lib/vimpack/utils/process.rb |
vimpack-0.0.3 | lib/vimpack/utils/process.rb |
vimpack-0.0.2 | lib/vimpack/utils/process.rb |
vimpack-0.0.1.1 | lib/vimpack/utils/process.rb |