frontkick 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93bb374c56521e783c36f3e8fb2dc6dce5e16747
4
- data.tar.gz: c24802f00fe4911982148fff88d6ae7609ec21a2
3
+ metadata.gz: 15b843028a22925691e8f1746f64512fcc4b5e41
4
+ data.tar.gz: 365e8d2f64e51103895af090c1ea5ef14cd66fb9
5
5
  SHA512:
6
- metadata.gz: c1dbd382e8c11c8cb220a4fe35cfb845c709aaa74b990abaf73e02d913cddca353143db60c96ac0f1c34aee3f516942b26bfbc23c8a0f58520cc67ae2966d63e
7
- data.tar.gz: 807825ab7a7b3157358cd3345d5a1bdf6a0e9c7ef3d5b9e1376db1beaa50365384f1d839c02986c40ad00388f03db1cb7464c8b042b9e4bcc6687ce2b9ceaf16
6
+ metadata.gz: dd1f32da4df783699687b209a3475f47f07dcf4b973090784a3601dc00ae2f07893300c08eb51b88e9c0df68b69b8987468dabb34a71c310631547a07c5838ec
7
+ data.tar.gz: 5e870eb23d7ccaba8655134131fac61f3653f8ac98bf1f16b0b30e68558474dfec6e28bfb5d16c611cb0537695836aa8acea5ba131b19b87912dcb7655f607f8
@@ -1,3 +1,9 @@
1
+ # 0.5.5 (2017/03/20)
2
+
3
+ Enhancements:
4
+
5
+ - Add :popen2e option
6
+
1
7
  # 0.5.4 (2017/01/12)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -70,12 +70,18 @@ ruby
70
70
  └─ echo
71
71
  ```
72
72
 
73
- NOTE: This interface is different with Kernel.spawn or Open3.popen3. They works with no shell if multiple arguments are given rather than an array as:
73
+ NOTE: This interface is different with Kernel.spawn or Open3.popen3, but similar to IO.popen. Kernel.spawn or Open3.popen3 works with no shell if multiple arguments are given:
74
74
 
75
75
  ```
76
76
  spawn('echo', '*')
77
77
  ```
78
78
 
79
+ IO.popen works with no shell if an array argument is given:
80
+
81
+ ```
82
+ IO.popen(['echo', '*'])
83
+ ```
84
+
79
85
  ### Environment Variables
80
86
 
81
87
  You can pass environment variables as a hash for the 1st argument as [spawn](https://ruby-doc.org/core-2.4.0/Kernel.html#method-i-spawn).
@@ -133,6 +139,15 @@ Frontkick.exec(["ls /something_not_found"], :out => out, :err => err)
133
139
 
134
140
  You can also give IO objects. In this case, result.stdout, and result.stderr are the given IO objects.
135
141
 
142
+ ### Popen2e Option (Get stdout and stderr together)
143
+
144
+ ```ruby
145
+ result = Frontkick.exec("echo foo; ls /something_not_found", :popen2e => true)
146
+ puts result.output #=>
147
+ foo
148
+ ls: /something_not_found: No such file or directory
149
+ ```
150
+
136
151
  ### Popen3 Options (such as :chdir)
137
152
 
138
153
  Other options such as :chdir are treated as options of `Open3.#popen3`.
@@ -0,0 +1,4 @@
1
+ require 'frontkick'
2
+
3
+ result = Frontkick.exec(["pwd; ls /something_not_found"], :chdir => '/', :popen2e => true)
4
+ puts result.output
@@ -0,0 +1,5 @@
1
+ require 'frontkick'
2
+
3
+ $stdout.sync = true
4
+ $stderr.sync = true
5
+ result = Frontkick.exec(["#{__dir__}/../experiment/redirect_child.rb"], out: $stdout, err: $stderr)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $stdout.sync = true
3
+
4
+ 5.times do |i|
5
+ $stdout.puts 'a' * 10
6
+ sleep 1
7
+ end
@@ -55,32 +55,52 @@ module Frontkick
55
55
  begin
56
56
  ::Timeout.timeout(opts[:timeout], Frontkick::TimeoutLocal) do # nil is for no timeout
57
57
  duration = Benchmark.realtime do
58
- stdin, stdout, stderr, wait_thr = Open3.popen3(env, *cmd_array, popen3_opts)
59
- out_thr = Thread.new {
60
- begin
61
- while true
62
- out.write stdout.readpartial(4096)
58
+ if opts[:popen2e]
59
+ stdin, stdout, wait_thr = Open3.popen2e(env, *cmd_array, popen3_opts)
60
+ out_thr = Thread.new {
61
+ begin
62
+ while true
63
+ out.write stdout.readpartial(4096)
64
+ end
65
+ rescue EOFError
63
66
  end
64
- rescue EOFError
65
- end
66
- }
67
- err_thr = Thread.new {
68
- begin
69
- while true
70
- err.write stderr.readpartial(4096)
67
+ }
68
+ stdin.close
69
+ pid = wait_thr.pid
70
+
71
+ yield(wait_thr) if block_given?
72
+
73
+ out_thr.join
74
+ exit_code = wait_thr.value.exitstatus
75
+ process_wait(pid)
76
+ else
77
+ stdin, stdout, stderr, wait_thr = Open3.popen3(env, *cmd_array, popen3_opts)
78
+ out_thr = Thread.new {
79
+ begin
80
+ while true
81
+ out.write stdout.readpartial(4096)
82
+ end
83
+ rescue EOFError
84
+ end
85
+ }
86
+ err_thr = Thread.new {
87
+ begin
88
+ while true
89
+ err.write stderr.readpartial(4096)
90
+ end
91
+ rescue EOFError
71
92
  end
72
- rescue EOFError
73
- end
74
- }
75
- stdin.close
76
- pid = wait_thr.pid
77
-
78
- yield(wait_thr) if block_given?
79
-
80
- out_thr.join
81
- err_thr.join
82
- exit_code = wait_thr.value.exitstatus
83
- process_wait(pid)
93
+ }
94
+ stdin.close
95
+ pid = wait_thr.pid
96
+
97
+ yield(wait_thr) if block_given?
98
+
99
+ out_thr.join
100
+ err_thr.join
101
+ exit_code = wait_thr.value.exitstatus
102
+ process_wait(pid)
103
+ end
84
104
  end
85
105
  end
86
106
  rescue Frontkick::TimeoutLocal => e
@@ -121,6 +141,7 @@ module Frontkick
121
141
  o.delete(:timeout)
122
142
  o.delete(:out)
123
143
  o.delete(:err)
144
+ o.delete(:popen2e)
124
145
  }
125
146
  end
126
147
 
@@ -1,3 +1,3 @@
1
1
  module Frontkick
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,7 +70,9 @@ files:
70
70
  - example/dry_run.rb
71
71
  - example/env.rb
72
72
  - example/kill_child.rb
73
+ - example/popen2e.rb
73
74
  - example/popen3_options.rb
75
+ - example/redirect.rb
74
76
  - example/redirect_without_shell.rb
75
77
  - example/run.rb
76
78
  - experiment/capture3_no_deadlock.rb
@@ -78,6 +80,7 @@ files:
78
80
  - experiment/cat_64k.rb
79
81
  - experiment/popen3_deadlock.rb
80
82
  - experiment/popen3_no_deadlock.rb
83
+ - experiment/redirect_child.rb
81
84
  - frontkick.gemspec
82
85
  - lib/frontkick.rb
83
86
  - lib/frontkick/command.rb
@@ -104,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
107
  version: '0'
105
108
  requirements: []
106
109
  rubyforge_project:
107
- rubygems_version: 2.4.5
110
+ rubygems_version: 2.5.1
108
111
  signing_key:
109
112
  specification_version: 4
110
113
  summary: Execute a command simply!