File: executor.rb

package info (click to toggle)
ruby-jekyll-last-modified-at 1.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 188 kB
  • sloc: ruby: 346; makefile: 4; sh: 3
file content (36 lines) | stat: -rw-r--r-- 752 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'posix/spawn'

module Jekyll
  module LastModifiedAt
    module Executor
      extend POSIX::Spawn

      def self.sh(*args)
        r, w = IO.pipe
        e, eo = IO.pipe
        pid = spawn(*args,
                    :out => w, r => :close,
                    :err => eo, e => :close)

        if pid.positive?
          w.close
          eo.close
          out = r.read
          err = e.read
          ::Process.waitpid(pid)
          "#{out} #{err}".strip if out
        end
      ensure
        [r, w, e, eo].each do |io|
          begin
                                   io.close
          rescue StandardError
            nil
                                 end
        end
      end
    end
  end
end