open4 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +41 -0
- data/lib/{open4-0.8.0.rb → open4-0.9.0.rb} +31 -22
- data/lib/open4.rb +31 -22
- metadata +3 -4
- data/open4-0.8.0.gem +0 -0
data/README
CHANGED
@@ -10,6 +10,47 @@ SYNOPSIS
|
|
10
10
|
|
11
11
|
HISTORY
|
12
12
|
|
13
|
+
0.9.0:
|
14
|
+
- added the ability for open4.spawn to take either an array of arguments
|
15
|
+
or multiple arguments in order to specify the argv for the command run.
|
16
|
+
for example
|
17
|
+
|
18
|
+
open4.spawn ['touch', 'difficult to "quote"'], :stdout=>STDOUT
|
19
|
+
|
20
|
+
same thing
|
21
|
+
|
22
|
+
open4.spawn 'touch', 'difficult to "quote"', :stdout=>STDOUT
|
23
|
+
|
24
|
+
thanks to jordan breeding for this suggestion
|
25
|
+
|
26
|
+
|
27
|
+
- added 'cwd'/:cwd keyword. usage is pretty obivous
|
28
|
+
|
29
|
+
open4.spawn 'pwd', 1=>STDOUT, :cwd=>'/tmp' #=> /tmp
|
30
|
+
|
31
|
+
this one also from jordan
|
32
|
+
|
33
|
+
0.8.0:
|
34
|
+
|
35
|
+
- fixed a critical bug whereby a process producing tons of stdout, but for
|
36
|
+
which the stdout was not handled, would cause the child process to
|
37
|
+
become blocked/hung writing to the pipe. eg, this command would cause a
|
38
|
+
hang
|
39
|
+
|
40
|
+
include Open4
|
41
|
+
|
42
|
+
spawn 'ruby -e" puts Array.new(65536){ 42 } "'
|
43
|
+
|
44
|
+
whereas this one would not
|
45
|
+
|
46
|
+
include Open4
|
47
|
+
|
48
|
+
spawn 'ruby -e" puts Array.new(65536){ 42 } "', :stdout=>StringIO.new
|
49
|
+
|
50
|
+
this version handles the former by spawning a 'null' thread which reads,
|
51
|
+
but does not process stdout/stderr. that way commands which generate
|
52
|
+
tons of output will never become blocked.
|
53
|
+
|
13
54
|
0.7.0:
|
14
55
|
- merged functionality of exitstatus/status keywords:
|
15
56
|
|
@@ -4,7 +4,7 @@ require 'thread'
|
|
4
4
|
|
5
5
|
module Open4
|
6
6
|
#--{{{
|
7
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.9.0'
|
8
8
|
def self.version() VERSION end
|
9
9
|
|
10
10
|
class Error < ::StandardError; end
|
@@ -235,8 +235,14 @@ module Open4
|
|
235
235
|
end
|
236
236
|
module_function :relay
|
237
237
|
|
238
|
-
def spawn
|
238
|
+
def spawn arg, *argv
|
239
239
|
#--{{{
|
240
|
+
argv.unshift(arg)
|
241
|
+
opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {})
|
242
|
+
argv.flatten!
|
243
|
+
cmd = argv.join(' ')
|
244
|
+
|
245
|
+
|
240
246
|
getopt = getopts opts
|
241
247
|
|
242
248
|
ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
|
@@ -251,6 +257,7 @@ module Open4
|
|
251
257
|
stdout_timeout = getopt[ %w( stdout_timeout io_timeout ) ]
|
252
258
|
stderr_timeout = getopt[ %w( stderr_timeout ) ]
|
253
259
|
status = getopt[ %w( status ) ]
|
260
|
+
cwd = getopt[ %w( cwd dir ), Dir.pwd ]
|
254
261
|
|
255
262
|
exitstatus =
|
256
263
|
case exitstatus
|
@@ -269,30 +276,32 @@ module Open4
|
|
269
276
|
|
270
277
|
status =
|
271
278
|
begin
|
272
|
-
|
273
|
-
|
274
|
-
|
279
|
+
Dir.chdir(cwd) do
|
280
|
+
Timeout::timeout(timeout) do
|
281
|
+
popen4(*argv) do |c, i, o, e|
|
282
|
+
started = true
|
275
283
|
|
276
|
-
|
277
|
-
|
278
|
-
|
284
|
+
%w( replace pid= << push update ).each do |msg|
|
285
|
+
break(pid.send(msg, c)) if pid.respond_to? msg
|
286
|
+
end
|
279
287
|
|
280
|
-
|
288
|
+
te = ThreadEnsemble.new c
|
281
289
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
290
|
+
te.add_thread(i, stdin) do |i, stdin|
|
291
|
+
relay stdin, i, stdin_timeout
|
292
|
+
i.close rescue nil
|
293
|
+
end
|
286
294
|
|
287
|
-
|
288
|
-
|
289
|
-
|
295
|
+
te.add_thread(o, stdout) do |o, stdout|
|
296
|
+
relay o, stdout, stdout_timeout
|
297
|
+
end
|
290
298
|
|
291
|
-
|
292
|
-
|
293
|
-
|
299
|
+
te.add_thread(e, stderr) do |o, stderr|
|
300
|
+
relay e, stderr, stderr_timeout
|
301
|
+
end
|
294
302
|
|
295
|
-
|
303
|
+
te.run
|
304
|
+
end
|
296
305
|
end
|
297
306
|
end
|
298
307
|
rescue
|
@@ -307,12 +316,12 @@ module Open4
|
|
307
316
|
end
|
308
317
|
module_function :spawn
|
309
318
|
|
310
|
-
def background
|
319
|
+
def background arg, *argv
|
311
320
|
#--{{{
|
312
321
|
require 'thread'
|
313
322
|
q = Queue.new
|
314
323
|
opts['pid'] = opts[:pid] = q
|
315
|
-
thread = Thread.new(
|
324
|
+
thread = Thread.new(arg, argv){|arg, argv| spawn arg, *argv}
|
316
325
|
pid = q.pop
|
317
326
|
sc = class << thread; self; end
|
318
327
|
sc.module_eval {
|
data/lib/open4.rb
CHANGED
@@ -4,7 +4,7 @@ require 'thread'
|
|
4
4
|
|
5
5
|
module Open4
|
6
6
|
#--{{{
|
7
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.9.0'
|
8
8
|
def self.version() VERSION end
|
9
9
|
|
10
10
|
class Error < ::StandardError; end
|
@@ -235,8 +235,14 @@ module Open4
|
|
235
235
|
end
|
236
236
|
module_function :relay
|
237
237
|
|
238
|
-
def spawn
|
238
|
+
def spawn arg, *argv
|
239
239
|
#--{{{
|
240
|
+
argv.unshift(arg)
|
241
|
+
opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {})
|
242
|
+
argv.flatten!
|
243
|
+
cmd = argv.join(' ')
|
244
|
+
|
245
|
+
|
240
246
|
getopt = getopts opts
|
241
247
|
|
242
248
|
ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
|
@@ -251,6 +257,7 @@ module Open4
|
|
251
257
|
stdout_timeout = getopt[ %w( stdout_timeout io_timeout ) ]
|
252
258
|
stderr_timeout = getopt[ %w( stderr_timeout ) ]
|
253
259
|
status = getopt[ %w( status ) ]
|
260
|
+
cwd = getopt[ %w( cwd dir ), Dir.pwd ]
|
254
261
|
|
255
262
|
exitstatus =
|
256
263
|
case exitstatus
|
@@ -269,30 +276,32 @@ module Open4
|
|
269
276
|
|
270
277
|
status =
|
271
278
|
begin
|
272
|
-
|
273
|
-
|
274
|
-
|
279
|
+
Dir.chdir(cwd) do
|
280
|
+
Timeout::timeout(timeout) do
|
281
|
+
popen4(*argv) do |c, i, o, e|
|
282
|
+
started = true
|
275
283
|
|
276
|
-
|
277
|
-
|
278
|
-
|
284
|
+
%w( replace pid= << push update ).each do |msg|
|
285
|
+
break(pid.send(msg, c)) if pid.respond_to? msg
|
286
|
+
end
|
279
287
|
|
280
|
-
|
288
|
+
te = ThreadEnsemble.new c
|
281
289
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
290
|
+
te.add_thread(i, stdin) do |i, stdin|
|
291
|
+
relay stdin, i, stdin_timeout
|
292
|
+
i.close rescue nil
|
293
|
+
end
|
286
294
|
|
287
|
-
|
288
|
-
|
289
|
-
|
295
|
+
te.add_thread(o, stdout) do |o, stdout|
|
296
|
+
relay o, stdout, stdout_timeout
|
297
|
+
end
|
290
298
|
|
291
|
-
|
292
|
-
|
293
|
-
|
299
|
+
te.add_thread(e, stderr) do |o, stderr|
|
300
|
+
relay e, stderr, stderr_timeout
|
301
|
+
end
|
294
302
|
|
295
|
-
|
303
|
+
te.run
|
304
|
+
end
|
296
305
|
end
|
297
306
|
end
|
298
307
|
rescue
|
@@ -307,12 +316,12 @@ module Open4
|
|
307
316
|
end
|
308
317
|
module_function :spawn
|
309
318
|
|
310
|
-
def background
|
319
|
+
def background arg, *argv
|
311
320
|
#--{{{
|
312
321
|
require 'thread'
|
313
322
|
q = Queue.new
|
314
323
|
opts['pid'] = opts[:pid] = q
|
315
|
-
thread = Thread.new(
|
324
|
+
thread = Thread.new(arg, argv){|arg, argv| spawn arg, *argv}
|
316
325
|
pid = q.pop
|
317
326
|
sc = class << thread; self; end
|
318
327
|
sc.module_eval {
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: open4
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.9.0
|
7
|
+
date: 2006-10-17 00:00:00.000000 -06:00
|
8
8
|
summary: open4
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- lib
|
35
35
|
- README
|
36
36
|
- gemspec.rb
|
37
|
-
- open4-0.8.0.gem
|
38
37
|
- sample/block.rb
|
39
38
|
- sample/simple.rb
|
40
39
|
- sample/exception.rb
|
@@ -43,7 +42,7 @@ files:
|
|
43
42
|
- sample/timeout.rb
|
44
43
|
- sample/stdin_timeout.rb
|
45
44
|
- lib/open4.rb
|
46
|
-
- lib/open4-0.
|
45
|
+
- lib/open4-0.9.0.rb
|
47
46
|
test_files: []
|
48
47
|
rdoc_options: []
|
49
48
|
extra_rdoc_files: []
|
data/open4-0.8.0.gem
DELETED
File without changes
|