/
command.rb
36 lines (33 loc) · 913 Bytes
/
command.rb
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
# need to use popen3 on windows - popen4 always eventually calls fork
if Lolcommits::Platform.platform_windows?
module Mercurial
class Command
private
def execution_proc
proc do
debug(command)
result = ''
error = ''
status = nil
Open3.popen3(command) do |_stdin, stdout, stderr, wait_thread|
Timeout.timeout(timeout) do
while (tmp = stdout.read(102_400))
result += tmp
end
end
while (tmp = stderr.read(1024))
error += tmp
end
status = if RUBY_VERSION =~ /^1\.8/
error.empty? ? 0 : 1
else
wait_thread.value
end
end
raise_error_if_needed(status, error)
result
end
end
end
end
end