|
1 |
| -begin |
2 |
| - require "posix-spawn" |
3 |
| -rescue LoadError |
4 |
| - require "open3" |
5 |
| -end |
6 |
| - |
| 1 | +require "open3" |
7 | 2 | require "github/markup/implementation"
|
8 | 3 |
|
9 | 4 |
|
@@ -39,28 +34,13 @@ def call_block(rendered, content)
|
39 | 34 | end
|
40 | 35 | end
|
41 | 36 |
|
42 |
| - if defined?(POSIX::Spawn) |
43 |
| - def execute(command, target) |
44 |
| - spawn = POSIX::Spawn::Child.new(*command, :input => target) |
45 |
| - if spawn.status.success? |
46 |
| - sanitize(spawn.out, target.encoding) |
47 |
| - else |
48 |
| - raise CommandError.new(spawn.err.strip) |
49 |
| - end |
50 |
| - end |
51 |
| - else |
52 |
| - def execute(command, target) |
53 |
| - output = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr| |
54 |
| - stdin.puts target |
55 |
| - stdin.close |
56 |
| - if wait_thr.value.success? |
57 |
| - stdout.readlines |
58 |
| - else |
59 |
| - raise CommandError.new(stderr.readlines.join('').strip) |
60 |
| - end |
61 |
| - end |
62 |
| - sanitize(output.join(''), target.encoding) |
63 |
| - end |
| 37 | + def execute(command, target) |
| 38 | + # capture3 blocks until both buffers are written to and the process terminates, but |
| 39 | + # it won't allow either buffer to fill up |
| 40 | + stdout, stderr, status = Open3.capture3(*command, stdin_data: target) |
| 41 | + |
| 42 | + raise CommandError.new(stderr) unless status.success? |
| 43 | + sanitize(stdout, target.encoding) |
64 | 44 | end
|
65 | 45 |
|
66 | 46 | def sanitize(input, encoding)
|
|
0 commit comments