process_watcher 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ProcessWatcher
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
@@ -31,6 +31,42 @@ module ProcessWatcher
31
31
  include ::Windows::Synchronize
32
32
  include ::Windows::Handle
33
33
 
34
+ # Quacks like Process::Status, which we cannot instantiate ourselves because
35
+ # has no public new method.
36
+ class Status
37
+ # Process ID
38
+ attr_reader :pid
39
+
40
+ # Process exit code
41
+ attr_reader :exitstatus
42
+
43
+ # === Parameters
44
+ # pid(Integer):: Process ID.
45
+ #
46
+ # exitstatus(Integer):: Process exit code
47
+ def initialize(pid, exitstatus)
48
+ @pid = pid
49
+ @exitstatus = exitstatus
50
+ end
51
+
52
+ # Simulates Process::Status.exited?
53
+ #
54
+ # === Returns
55
+ # true in all cases because this object cannot be returned until the
56
+ # process exits
57
+ def exited?
58
+ return true
59
+ end
60
+
61
+ # Simulates Process::Status.success?
62
+ #
63
+ # === Returns
64
+ # true if the process returned zero as its exit code
65
+ def success?
66
+ return @exitstatus ? (0 == @exitstatus) : true;
67
+ end
68
+ end
69
+
34
70
  # Spawn given process and callback given block with output and exit code
35
71
  #
36
72
  # === Parameters
@@ -58,10 +94,12 @@ module ProcessWatcher
58
94
  case @handle
59
95
  when INVALID_HANDLE_VALUE
60
96
  # Something bad happened
61
- yield(:exit_code => 1)
97
+ exit_code = 1
98
+ yield(:exit_code => exit_code, :exit_status => Status.new(@io.pid, exit_code))
62
99
  when 0
63
100
  # Process already finished
64
- yield(:exit_code => 0)
101
+ exit_code = 0
102
+ yield(:exit_code => exit_code, :exit_status => Status.new(@io.pid, exit_code))
65
103
  else
66
104
  # Start output read
67
105
  @reader = Thread.new do
@@ -77,7 +115,7 @@ module ProcessWatcher
77
115
  else
78
116
  exit_code = 1
79
117
  end
80
- yield(:exit_code => exit_code)
118
+ yield(:exit_code => exit_code, :exit_status => Status.new(@io.pid, exit_code))
81
119
  end
82
120
  end
83
121
  @io.pid
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: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- version: "0.3"
8
+ - 4
9
+ version: "0.4"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Graham Hughes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-08 00:00:00 -08:00
18
+ date: 2010-11-29 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency