blue_shell 0.0.2 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ module BlueShell
12
12
  # Execute the given command. Will block until the command completes.
13
13
  # param [String] the command to execute in bash
14
14
  # param [Integer] the number of seconds to wait for it to complete
15
- def execute!(command, timeout = 5)
15
+ def execute!(command, timeout = 30)
16
16
  # Executing via a file seems clunky, but it is the best way to
17
17
  # ensure everything happens exactly as we expect it to without
18
18
  # trying to deal with escaping the world properly.
@@ -22,10 +22,19 @@ module BlueShell
22
22
  file.flush
23
23
 
24
24
  Timeout::timeout(timeout) do
25
- @proc = runtime.exec("/bin/bash #{file.path}")
26
- @out = stream_to_string(@proc.getInputStream)
27
- @err = stream_to_string(@proc.getErrorStream)
28
- @exit = @proc.exitValue
25
+ proc = runtime.exec("/bin/bash #{file.path}")
26
+
27
+ @out = ""
28
+ @err = ""
29
+
30
+ # Must have a sink for stdout for the proc to exit
31
+ out_thread = read_thread(proc.getInputStream, @out)
32
+ err_thread = read_thread(proc.getErrorStream, @err)
33
+
34
+ out_thread.join
35
+ err_thread.join
36
+
37
+ @exit = proc.exitValue
29
38
  end
30
39
  ensure
31
40
  file.close
@@ -33,18 +42,17 @@ module BlueShell
33
42
  end
34
43
  end
35
44
 
36
- def stream_to_string(stream)
37
- br = BufferedReader.new(InputStreamReader.new(stream))
38
- line = nil
39
- lines = []
45
+ def read_thread(stream, sink)
46
+ Thread.new(stream, sink) do |stream, sink|
47
+ line = nil
48
+ br = BufferedReader.new(InputStreamReader.new(stream))
40
49
 
41
- while(line = br.readLine) do
42
- lines << line
50
+ while(line = br.readLine) do
51
+ sink << line
52
+ end
43
53
  end
44
-
45
- lines.join("\n")
46
54
  end
47
- private :stream_to_string
55
+ private :read_thread
48
56
 
49
57
  def runtime
50
58
  @runtime ||= java.lang.Runtime.getRuntime
@@ -1,3 +1,3 @@
1
1
  module BlueShell
2
- VERSION = "0.0.2"
2
+ VERSION = "0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blue_shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: '0.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: