subprocess 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Subprocess
2
2
  ==========
3
3
 
4
+ ![Jacques Cousteau Submarine](http://i.imgur.com/lmej24F.jpg)
5
+
4
6
  A port of Python's excellent subprocess module to Ruby.
5
7
 
6
8
  Many thanks to [Bram Swenson][bram], the author of the old [subprocess][old]
@@ -98,7 +98,6 @@ module Subprocess
98
98
  # @return [String] Text interpretation
99
99
  #
100
100
  def self.status_to_s(status, convert_high_exit=true)
101
-
102
101
  # use an array just in case we somehow get a status with all the bits set
103
102
  parts = []
104
103
  if status.exited?
@@ -109,17 +108,15 @@ module Subprocess
109
108
  sig_num = status.exitstatus - 128
110
109
 
111
110
  # sigh, why is ruby so silly
112
- begin
111
+ if Signal.respond_to?(:signame)
113
112
  # ruby 2.0 way
114
113
  sig_name = Signal.signame(sig_num)
115
- rescue NoMethodError
116
- begin
117
- # ruby 1.9 way
118
- sig_name = Signal.list.key(sig_num)
119
- rescue NoMethodError
120
- # ruby 1.8 way
121
- sig_name = Signal.list.index(sig_num)
122
- end
114
+ elsif Signal.list.respond_to?(:key)
115
+ # ruby 1.9 way
116
+ sig_name = Signal.list.key(sig_num)
117
+ else
118
+ # ruby 1.8 way
119
+ sig_name = Signal.list.index(sig_num)
123
120
  end
124
121
 
125
122
  if sig_name
@@ -198,7 +195,8 @@ module Subprocess
198
195
  # Create a new process.
199
196
  #
200
197
  # @param [Array<String>] cmd The command to run and its arguments (in the
201
- # style of an `argv` array).
198
+ # style of an `argv` array). Unlike Python's subprocess module, `cmd`
199
+ # cannnot be a String.
202
200
  #
203
201
  # @option opts [IO, Fixnum, String, Subprocess::PIPE, nil] :stdin The `IO`,
204
202
  # file descriptor number, or file name to use for the process's standard
@@ -236,6 +234,8 @@ module Subprocess
236
234
  # in conjunction with {Subprocess::check_call}.
237
235
  # @yieldparam process [Process] The process that was just spawned.
238
236
  def initialize(cmd, opts={}, &blk)
237
+ raise ArgumentError, "cmd must be an Array" unless Array === cmd
238
+
239
239
  @command = cmd
240
240
 
241
241
  # Figure out what file descriptors we should pass on to the child (and
@@ -369,6 +369,9 @@ module Subprocess
369
369
  begin
370
370
  e = Marshal.load(control_r)
371
371
  e = "Unknown Failure" unless e.is_a?(Exception) || e.is_a?(String)
372
+ # Because we're throwing an exception and not returning a
373
+ # Process, we need to make sure the child gets reaped
374
+ wait
372
375
  raise e
373
376
  rescue EOFError # Nothing to read? Great!
374
377
  ensure
@@ -509,18 +512,21 @@ module Subprocess
509
512
  end
510
513
 
511
514
  private
512
- # Return a pair of values (child, ext), which are how the given file
513
- # descriptor should appear to the child and the external world. ext is only
514
- # non-nil in the case of a pipe (in fact, we just return a list of length
515
- # one, since ruby will unpack nils from missing list items).
515
+ # Return a pair of values (child, mine), which are how the given file
516
+ # descriptor should appear to the child and to this process, respectively.
517
+ # "mine" is only non-nil in the case of a pipe (in fact, we just return a
518
+ # list of length one, since ruby will unpack nils from missing list items).
519
+ #
520
+ # If you pass either an IO or an Integer (i.e., a raw file descriptor), a
521
+ # private copy of it will be made using `#dup`.
516
522
  def parse_fd(fd, mode)
517
- ret = case fd
523
+ fds = case fd
518
524
  when PIPE
519
525
  IO.pipe
520
526
  when IO
521
- [fd]
527
+ [fd.dup]
522
528
  when Integer
523
- [IO.new(fd, mode)]
529
+ [IO.new(fd, mode).dup]
524
530
  when String
525
531
  [File.open(fd, mode)]
526
532
  when nil
@@ -529,7 +535,7 @@ module Subprocess
529
535
  raise ArgumentError
530
536
  end
531
537
 
532
- mode == 'r' ? ret : ret.reverse
538
+ mode == 'r' ? fds : fds.reverse
533
539
  end
534
540
 
535
541
  def mark_fd_cloexec(fd)
@@ -1,3 +1,3 @@
1
1
  module Subprocess
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subprocess
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-10-19 00:00:00.000000000 Z
16
+ date: 2014-04-30 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: minitest
@@ -74,8 +74,8 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - lib/subprocess.rb
78
77
  - lib/subprocess/version.rb
78
+ - lib/subprocess.rb
79
79
  - README.md
80
80
  homepage: https://github.com/stripe/subprocess
81
81
  licenses:
@@ -90,18 +90,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  - - ! '>='
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
- segments:
94
- - 0
95
- hash: 84211792966870882
96
93
  required_rubygems_version: !ruby/object:Gem::Requirement
97
94
  none: false
98
95
  requirements:
99
96
  - - ! '>='
100
97
  - !ruby/object:Gem::Version
101
98
  version: '0'
102
- segments:
103
- - 0
104
- hash: 84211792966870882
105
99
  requirements: []
106
100
  rubyforge_project:
107
101
  rubygems_version: 1.8.23
@@ -109,3 +103,4 @@ signing_key:
109
103
  specification_version: 3
110
104
  summary: A port of Python's subprocess module to Ruby
111
105
  test_files: []
106
+ has_rdoc: