process_watcher 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -51,7 +51,7 @@ module ProcessWatcher
|
|
51
51
|
@pid = fork do
|
52
52
|
oldstderr = STDERR.clone
|
53
53
|
pr.close
|
54
|
-
STDIN.
|
54
|
+
STDIN.close
|
55
55
|
STDOUT.reopen(pw)
|
56
56
|
STDERR.reopen(pw)
|
57
57
|
begin
|
@@ -76,14 +76,14 @@ module ProcessWatcher
|
|
76
76
|
# ass, the real one should depend on the kernel's buffer
|
77
77
|
# sizes.
|
78
78
|
result = fdes.readpartial(4096)
|
79
|
-
yield(:output => result)
|
79
|
+
yield(:output => result) if block_given?
|
80
80
|
end
|
81
81
|
end unless array.nil?
|
82
82
|
array[2].each do |fdes|
|
83
83
|
# Do something with erroneous condition.
|
84
84
|
end unless array.nil?
|
85
85
|
end
|
86
|
-
yield(:exit_code => $?.exitstatus, :exit_status => $?)
|
86
|
+
yield(:exit_code => $?.exitstatus, :exit_status => $?) if block_given?
|
87
87
|
end
|
88
88
|
|
89
89
|
return @pid
|
@@ -94,8 +94,8 @@ module ProcessWatcher
|
|
94
94
|
# === Return
|
95
95
|
# true:: Always return true
|
96
96
|
def cleanup
|
97
|
-
@reader.join
|
98
|
-
@io.close
|
97
|
+
@reader.join if @reader
|
98
|
+
@io.close if @io && !@io.closed?
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright: Copyright (c) 2010 RightScale, Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# 'Software'), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
25
|
+
|
26
|
+
describe ProcessWatcher::ProcessMonitor do
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
@monitor = ProcessWatcher::ProcessMonitor.new
|
30
|
+
end
|
31
|
+
|
32
|
+
after(:each) do
|
33
|
+
@monitor.cleanup
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should launch and watch well-behaved processes' do
|
37
|
+
ruby = "puts 42; exit 42"
|
38
|
+
times = 0
|
39
|
+
pid = @monitor.spawn('ruby', '-e', ruby) do |hash|
|
40
|
+
case times
|
41
|
+
when 0 then hash.should == {:output => "42\n"}
|
42
|
+
when 1 then hash[:exit_code].should == 42
|
43
|
+
hash[:exit_status].should_not be_nil
|
44
|
+
else fail "Shouldn't see more than two ticks"
|
45
|
+
end
|
46
|
+
times += 1
|
47
|
+
end
|
48
|
+
@monitor.cleanup
|
49
|
+
lambda { Process.kill(0, pid) }.should raise_exception(Errno::ESRCH)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should launch processes where we don\'t care about output' do
|
53
|
+
ruby = "puts 42; exit 42"
|
54
|
+
times = 0
|
55
|
+
pid = @monitor.spawn('ruby', '-e', ruby)
|
56
|
+
@monitor.cleanup
|
57
|
+
lambda { Process.kill(0, pid) }.should raise_exception(Errno::ESRCH)
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_watcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Graham Hughes
|
@@ -15,14 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-08 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
22
|
name: rspec
|
25
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
25
|
none: false
|
27
26
|
requirements:
|
28
27
|
- - ~>
|
@@ -32,7 +31,8 @@ dependencies:
|
|
32
31
|
- 1
|
33
32
|
- 3
|
34
33
|
version: "1.3"
|
35
|
-
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
36
|
description: |
|
37
37
|
ProcessWatcher is a cross platform interface for running subprocesses
|
38
38
|
safely. Unlike backticks or popen in Ruby 1.8, it will not invoke a
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/process_watcher/watcher.rb
|
61
61
|
- lib/process_watcher/win32/process_monitor.rb
|
62
62
|
- process_watcher.gemspec
|
63
|
+
- spec/process_watcher/monitor_spec.rb
|
63
64
|
- spec/process_watcher/watcher_spec.rb
|
64
65
|
- spec/process_watcher_spec.rb
|
65
66
|
- spec/rcov.opts
|
@@ -100,6 +101,7 @@ signing_key:
|
|
100
101
|
specification_version: 3
|
101
102
|
summary: Cross platform interface to running subprocesses
|
102
103
|
test_files:
|
104
|
+
- spec/process_watcher/monitor_spec.rb
|
103
105
|
- spec/process_watcher/watcher_spec.rb
|
104
106
|
- spec/process_watcher_spec.rb
|
105
107
|
- spec/rcov.opts
|