childprocess 0.8.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.document +6 -6
  3. data/.gitignore +28 -28
  4. data/.rspec +1 -1
  5. data/.travis.yml +40 -36
  6. data/CHANGELOG.md +73 -44
  7. data/Gemfile +21 -15
  8. data/LICENSE +20 -20
  9. data/README.md +218 -192
  10. data/Rakefile +61 -61
  11. data/appveyor.yml +42 -43
  12. data/childprocess.gemspec +26 -30
  13. data/lib/childprocess.rb +210 -205
  14. data/lib/childprocess/abstract_io.rb +36 -36
  15. data/lib/childprocess/abstract_process.rb +192 -192
  16. data/lib/childprocess/errors.rb +37 -26
  17. data/lib/childprocess/jruby.rb +56 -56
  18. data/lib/childprocess/jruby/io.rb +16 -16
  19. data/lib/childprocess/jruby/process.rb +184 -159
  20. data/lib/childprocess/jruby/pump.rb +53 -53
  21. data/lib/childprocess/tools/generator.rb +145 -145
  22. data/lib/childprocess/unix.rb +9 -9
  23. data/lib/childprocess/unix/fork_exec_process.rb +78 -70
  24. data/lib/childprocess/unix/io.rb +21 -21
  25. data/lib/childprocess/unix/lib.rb +186 -186
  26. data/lib/childprocess/unix/platform/i386-linux.rb +12 -12
  27. data/lib/childprocess/unix/platform/i386-solaris.rb +11 -11
  28. data/lib/childprocess/unix/platform/x86_64-linux.rb +12 -12
  29. data/lib/childprocess/unix/platform/x86_64-macosx.rb +11 -11
  30. data/lib/childprocess/unix/posix_spawn_process.rb +134 -134
  31. data/lib/childprocess/unix/process.rb +90 -89
  32. data/lib/childprocess/version.rb +3 -3
  33. data/lib/childprocess/windows.rb +38 -33
  34. data/lib/childprocess/windows/handle.rb +91 -91
  35. data/lib/childprocess/windows/io.rb +25 -25
  36. data/lib/childprocess/windows/lib.rb +416 -416
  37. data/lib/childprocess/windows/process.rb +130 -130
  38. data/lib/childprocess/windows/process_builder.rb +178 -175
  39. data/lib/childprocess/windows/structs.rb +148 -148
  40. data/spec/abstract_io_spec.rb +12 -12
  41. data/spec/childprocess_spec.rb +447 -391
  42. data/spec/get_env.ps1 +13 -0
  43. data/spec/io_spec.rb +228 -228
  44. data/spec/jruby_spec.rb +24 -24
  45. data/spec/pid_behavior.rb +12 -12
  46. data/spec/platform_detection_spec.rb +86 -86
  47. data/spec/spec_helper.rb +270 -261
  48. data/spec/unix_spec.rb +57 -57
  49. data/spec/windows_spec.rb +23 -23
  50. metadata +8 -39
@@ -1,36 +1,36 @@
1
- module ChildProcess
2
- class AbstractIO
3
- attr_reader :stderr, :stdout, :stdin
4
-
5
- def inherit!
6
- @stdout = STDOUT
7
- @stderr = STDERR
8
- end
9
-
10
- def stderr=(io)
11
- check_type io
12
- @stderr = io
13
- end
14
-
15
- def stdout=(io)
16
- check_type io
17
- @stdout = io
18
- end
19
-
20
- #
21
- # @api private
22
- #
23
-
24
- def _stdin=(io)
25
- check_type io
26
- @stdin = io
27
- end
28
-
29
- private
30
-
31
- def check_type(io)
32
- raise SubclassResponsibility, "check_type"
33
- end
34
-
35
- end
36
- end
1
+ module ChildProcess
2
+ class AbstractIO
3
+ attr_reader :stderr, :stdout, :stdin
4
+
5
+ def inherit!
6
+ @stdout = STDOUT
7
+ @stderr = STDERR
8
+ end
9
+
10
+ def stderr=(io)
11
+ check_type io
12
+ @stderr = io
13
+ end
14
+
15
+ def stdout=(io)
16
+ check_type io
17
+ @stdout = io
18
+ end
19
+
20
+ #
21
+ # @api private
22
+ #
23
+
24
+ def _stdin=(io)
25
+ check_type io
26
+ @stdin = io
27
+ end
28
+
29
+ private
30
+
31
+ def check_type(io)
32
+ raise SubclassResponsibility, "check_type"
33
+ end
34
+
35
+ end
36
+ end
@@ -1,192 +1,192 @@
1
- module ChildProcess
2
- class AbstractProcess
3
- POLL_INTERVAL = 0.1
4
-
5
- attr_reader :exit_code
6
-
7
- #
8
- # Set this to true if you do not care about when or if the process quits.
9
- #
10
- attr_accessor :detach
11
-
12
- #
13
- # Set this to true if you want to write to the process' stdin (process.io.stdin)
14
- #
15
- attr_accessor :duplex
16
-
17
- #
18
- # Modify the child's environment variables
19
- #
20
- attr_reader :environment
21
-
22
- #
23
- # Set the child's current working directory.
24
- #
25
- attr_accessor :cwd
26
-
27
- #
28
- # Set this to true to make the child process the leader of a new process group
29
- #
30
- # This can be used to make sure that all grandchildren are killed
31
- # when the child process dies.
32
- #
33
- attr_accessor :leader
34
-
35
- #
36
- # Create a new process with the given args.
37
- #
38
- # @api private
39
- # @see ChildProcess.build
40
- #
41
-
42
- def initialize(args)
43
- unless args.all? { |e| e.kind_of?(String) }
44
- raise ArgumentError, "all arguments must be String: #{args.inspect}"
45
- end
46
-
47
- @args = args
48
- @started = false
49
- @exit_code = nil
50
- @io = nil
51
- @cwd = nil
52
- @detach = false
53
- @duplex = false
54
- @leader = false
55
- @environment = {}
56
- end
57
-
58
- #
59
- # Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
60
- #
61
-
62
- def io
63
- raise SubclassResponsibility, "io"
64
- end
65
-
66
- #
67
- # @return [Integer] the pid of the process after it has started
68
- #
69
-
70
- def pid
71
- raise SubclassResponsibility, "pid"
72
- end
73
-
74
- #
75
- # Launch the child process
76
- #
77
- # @return [AbstractProcess] self
78
- #
79
-
80
- def start
81
- launch_process
82
- @started = true
83
-
84
- self
85
- end
86
-
87
- #
88
- # Forcibly terminate the process, using increasingly harsher methods if possible.
89
- #
90
- # @param [Integer] timeout (3) Seconds to wait before trying the next method.
91
- #
92
-
93
- def stop(timeout = 3)
94
- raise SubclassResponsibility, "stop"
95
- end
96
-
97
- #
98
- # Block until the process has been terminated.
99
- #
100
- # @return [Integer] The exit status of the process
101
- #
102
-
103
- def wait
104
- raise SubclassResponsibility, "wait"
105
- end
106
-
107
- #
108
- # Did the process exit?
109
- #
110
- # @return [Boolean]
111
- #
112
-
113
- def exited?
114
- raise SubclassResponsibility, "exited?"
115
- end
116
-
117
- #
118
- # Has the process started?
119
- #
120
- # @return [Boolean]
121
- #
122
-
123
- def started?
124
- @started
125
- end
126
-
127
- #
128
- # Is this process running?
129
- #
130
- # @return [Boolean]
131
- #
132
-
133
- def alive?
134
- started? && !exited?
135
- end
136
-
137
- #
138
- # Returns true if the process has exited and the exit code was not 0.
139
- #
140
- # @return [Boolean]
141
- #
142
-
143
- def crashed?
144
- exited? && @exit_code != 0
145
- end
146
-
147
- #
148
- # Wait for the process to exit, raising a ChildProcess::TimeoutError if
149
- # the timeout expires.
150
- #
151
-
152
- def poll_for_exit(timeout)
153
- log "polling #{timeout} seconds for exit"
154
-
155
- end_time = Time.now + timeout
156
- until (ok = exited?) || Time.now > end_time
157
- sleep POLL_INTERVAL
158
- end
159
-
160
- unless ok
161
- raise TimeoutError, "process still alive after #{timeout} seconds"
162
- end
163
- end
164
-
165
- private
166
-
167
- def launch_process
168
- raise SubclassResponsibility, "launch_process"
169
- end
170
-
171
- def detach?
172
- @detach
173
- end
174
-
175
- def duplex?
176
- @duplex
177
- end
178
-
179
- def leader?
180
- @leader
181
- end
182
-
183
- def log(*args)
184
- ChildProcess.logger.debug "#{self.inspect} : #{args.inspect}"
185
- end
186
-
187
- def assert_started
188
- raise Error, "process not started" unless started?
189
- end
190
-
191
- end # AbstractProcess
192
- end # ChildProcess
1
+ module ChildProcess
2
+ class AbstractProcess
3
+ POLL_INTERVAL = 0.1
4
+
5
+ attr_reader :exit_code
6
+
7
+ #
8
+ # Set this to true if you do not care about when or if the process quits.
9
+ #
10
+ attr_accessor :detach
11
+
12
+ #
13
+ # Set this to true if you want to write to the process' stdin (process.io.stdin)
14
+ #
15
+ attr_accessor :duplex
16
+
17
+ #
18
+ # Modify the child's environment variables
19
+ #
20
+ attr_reader :environment
21
+
22
+ #
23
+ # Set the child's current working directory.
24
+ #
25
+ attr_accessor :cwd
26
+
27
+ #
28
+ # Set this to true to make the child process the leader of a new process group
29
+ #
30
+ # This can be used to make sure that all grandchildren are killed
31
+ # when the child process dies.
32
+ #
33
+ attr_accessor :leader
34
+
35
+ #
36
+ # Create a new process with the given args.
37
+ #
38
+ # @api private
39
+ # @see ChildProcess.build
40
+ #
41
+
42
+ def initialize(args)
43
+ unless args.all? { |e| e.kind_of?(String) }
44
+ raise ArgumentError, "all arguments must be String: #{args.inspect}"
45
+ end
46
+
47
+ @args = args
48
+ @started = false
49
+ @exit_code = nil
50
+ @io = nil
51
+ @cwd = nil
52
+ @detach = false
53
+ @duplex = false
54
+ @leader = false
55
+ @environment = {}
56
+ end
57
+
58
+ #
59
+ # Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
60
+ #
61
+
62
+ def io
63
+ raise SubclassResponsibility, "io"
64
+ end
65
+
66
+ #
67
+ # @return [Integer] the pid of the process after it has started
68
+ #
69
+
70
+ def pid
71
+ raise SubclassResponsibility, "pid"
72
+ end
73
+
74
+ #
75
+ # Launch the child process
76
+ #
77
+ # @return [AbstractProcess] self
78
+ #
79
+
80
+ def start
81
+ launch_process
82
+ @started = true
83
+
84
+ self
85
+ end
86
+
87
+ #
88
+ # Forcibly terminate the process, using increasingly harsher methods if possible.
89
+ #
90
+ # @param [Integer] timeout (3) Seconds to wait before trying the next method.
91
+ #
92
+
93
+ def stop(timeout = 3)
94
+ raise SubclassResponsibility, "stop"
95
+ end
96
+
97
+ #
98
+ # Block until the process has been terminated.
99
+ #
100
+ # @return [Integer] The exit status of the process
101
+ #
102
+
103
+ def wait
104
+ raise SubclassResponsibility, "wait"
105
+ end
106
+
107
+ #
108
+ # Did the process exit?
109
+ #
110
+ # @return [Boolean]
111
+ #
112
+
113
+ def exited?
114
+ raise SubclassResponsibility, "exited?"
115
+ end
116
+
117
+ #
118
+ # Has the process started?
119
+ #
120
+ # @return [Boolean]
121
+ #
122
+
123
+ def started?
124
+ @started
125
+ end
126
+
127
+ #
128
+ # Is this process running?
129
+ #
130
+ # @return [Boolean]
131
+ #
132
+
133
+ def alive?
134
+ started? && !exited?
135
+ end
136
+
137
+ #
138
+ # Returns true if the process has exited and the exit code was not 0.
139
+ #
140
+ # @return [Boolean]
141
+ #
142
+
143
+ def crashed?
144
+ exited? && @exit_code != 0
145
+ end
146
+
147
+ #
148
+ # Wait for the process to exit, raising a ChildProcess::TimeoutError if
149
+ # the timeout expires.
150
+ #
151
+
152
+ def poll_for_exit(timeout)
153
+ log "polling #{timeout} seconds for exit"
154
+
155
+ end_time = Time.now + timeout
156
+ until (ok = exited?) || Time.now > end_time
157
+ sleep POLL_INTERVAL
158
+ end
159
+
160
+ unless ok
161
+ raise TimeoutError, "process still alive after #{timeout} seconds"
162
+ end
163
+ end
164
+
165
+ private
166
+
167
+ def launch_process
168
+ raise SubclassResponsibility, "launch_process"
169
+ end
170
+
171
+ def detach?
172
+ @detach
173
+ end
174
+
175
+ def duplex?
176
+ @duplex
177
+ end
178
+
179
+ def leader?
180
+ @leader
181
+ end
182
+
183
+ def log(*args)
184
+ ChildProcess.logger.debug "#{self.inspect} : #{args.inspect}"
185
+ end
186
+
187
+ def assert_started
188
+ raise Error, "process not started" unless started?
189
+ end
190
+
191
+ end # AbstractProcess
192
+ end # ChildProcess