childprocess 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → README.md} +21 -16
- data/childprocess.gemspec +1 -0
- data/lib/childprocess/version.rb +1 -1
- data/lib/childprocess/windows/process.rb +18 -4
- data/spec/childprocess_spec.rb +13 -0
- metadata +18 -33
data/{README.rdoc → README.md}
RENAMED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
childprocess
|
2
|
+
============
|
2
3
|
|
3
4
|
This gem aims at being a simple and reliable solution for controlling
|
4
5
|
external programs running in the background on any Ruby / OS combination.
|
@@ -6,26 +7,29 @@ external programs running in the background on any Ruby / OS combination.
|
|
6
7
|
The code originated in the selenium-webdriver gem, but should prove useful as
|
7
8
|
a standalone library.
|
8
9
|
|
9
|
-
|
10
|
+
Usage
|
11
|
+
-----
|
12
|
+
```ruby
|
13
|
+
process = ChildProcess.build("ruby", "-e", "sleep")
|
10
14
|
|
11
|
-
|
15
|
+
# inherit stdout/stderr from parent
|
16
|
+
process.io.inherit!
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
# or pass an IO
|
19
|
+
process.io.stdout = Tempfile.new("child-output")
|
15
20
|
|
16
|
-
|
17
|
-
process.io.stdout = Tempfile.new("child-output")
|
21
|
+
process.start
|
18
22
|
|
19
|
-
|
23
|
+
process.alive? #=> true
|
24
|
+
process.exited? #=> false
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
process.stop
|
26
|
+
process.stop
|
27
|
+
```
|
25
28
|
|
26
29
|
The object returned from ChildProcess.build will implement ChildProcess::AbstractProcess.
|
27
30
|
|
28
|
-
|
31
|
+
Implementation
|
32
|
+
--------------
|
29
33
|
|
30
34
|
How the process is launched and killed depends on the platform:
|
31
35
|
|
@@ -34,8 +38,8 @@ How the process is launched and killed depends on the platform:
|
|
34
38
|
* JRuby : java.lang.{Process,ProcessBuilder}
|
35
39
|
* IronRuby : System.Diagnostics.Process
|
36
40
|
|
37
|
-
|
38
|
-
|
41
|
+
Note on Patches/Pull Requests
|
42
|
+
-----------------------------
|
39
43
|
|
40
44
|
* Fork the project.
|
41
45
|
* Make your feature addition or bug fix.
|
@@ -45,6 +49,7 @@ How the process is launched and killed depends on the platform:
|
|
45
49
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
46
50
|
* Send me a pull request. Bonus points for topic branches.
|
47
51
|
|
48
|
-
|
52
|
+
Copyright
|
53
|
+
---------
|
49
54
|
|
50
55
|
Copyright (c) 2010-2011 Jari Bakken. See LICENSE for details.
|
data/childprocess.gemspec
CHANGED
data/lib/childprocess/version.rb
CHANGED
@@ -52,10 +52,7 @@ module ChildProcess
|
|
52
52
|
opts[:stderr] = @io.stderr
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
command = @args.join ' '
|
57
|
-
|
58
|
-
@pid = Lib.create_proc(command, opts)
|
55
|
+
@pid = Lib.create_proc(command_string, opts)
|
59
56
|
@handle = Handle.open(@pid)
|
60
57
|
|
61
58
|
if duplex?
|
@@ -65,6 +62,23 @@ module ChildProcess
|
|
65
62
|
self
|
66
63
|
end
|
67
64
|
|
65
|
+
def command_string
|
66
|
+
@command_string ||= (
|
67
|
+
@args.map { |arg| quote_if_necessary(arg.to_s) }.join ' '
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def quote_if_necessary(str)
|
72
|
+
quote = str.start_with?('"') ? "'" : '"'
|
73
|
+
|
74
|
+
case str
|
75
|
+
when /[\s\\'"]/
|
76
|
+
%{#{quote}#{str}#{quote}}
|
77
|
+
else
|
78
|
+
str
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
68
82
|
end # Process
|
69
83
|
end # Windows
|
70
84
|
end # ChildProcess
|
data/spec/childprocess_spec.rb
CHANGED
@@ -165,4 +165,17 @@ describe ChildProcess do
|
|
165
165
|
Dir.rmdir(path) if File.exist?(path)
|
166
166
|
end
|
167
167
|
end
|
168
|
+
|
169
|
+
it "can handle whitespace, special characters and quotes in arguments" do
|
170
|
+
args = ["foo bar", 'foo\bar', "'i-am-quoted'", '"i am double quoted"']
|
171
|
+
|
172
|
+
Tempfile.open("argv-spec") do |file|
|
173
|
+
process = write_argv(file.path, *args).start
|
174
|
+
process.poll_for_exit(EXIT_TIMEOUT)
|
175
|
+
|
176
|
+
file.rewind
|
177
|
+
file.read.should == args.inspect
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
168
181
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: childprocess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 9
|
10
|
-
version: 0.1.9
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Jari Bakken
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-07-20 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
16
|
name: rspec
|
@@ -26,11 +20,6 @@ dependencies:
|
|
26
20
|
requirements:
|
27
21
|
- - ">="
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
- 0
|
34
23
|
version: 2.0.0
|
35
24
|
type: :development
|
36
25
|
version_requirements: *id001
|
@@ -42,28 +31,31 @@ dependencies:
|
|
42
31
|
requirements:
|
43
32
|
- - ">="
|
44
33
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
34
|
version: "0"
|
49
35
|
type: :development
|
50
36
|
version_requirements: *id002
|
51
37
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
38
|
+
name: rake
|
53
39
|
prerelease: false
|
54
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
41
|
none: false
|
56
42
|
requirements:
|
57
43
|
- - ~>
|
58
44
|
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
45
|
+
version: 0.8.7
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: ffi
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
64
56
|
version: 1.0.6
|
65
57
|
type: :runtime
|
66
|
-
version_requirements: *
|
58
|
+
version_requirements: *id004
|
67
59
|
description: This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.
|
68
60
|
email:
|
69
61
|
- jari.bakken@gmail.com
|
@@ -79,7 +71,7 @@ files:
|
|
79
71
|
- .rspec
|
80
72
|
- Gemfile
|
81
73
|
- LICENSE
|
82
|
-
- README.
|
74
|
+
- README.md
|
83
75
|
- Rakefile
|
84
76
|
- childprocess.gemspec
|
85
77
|
- lib/childprocess.rb
|
@@ -111,7 +103,6 @@ files:
|
|
111
103
|
- spec/spec_helper.rb
|
112
104
|
- spec/unix_spec.rb
|
113
105
|
- spec/windows_spec.rb
|
114
|
-
has_rdoc: true
|
115
106
|
homepage: http://github.com/jarib/childprocess
|
116
107
|
licenses: []
|
117
108
|
|
@@ -125,23 +116,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
116
|
requirements:
|
126
117
|
- - ">="
|
127
118
|
- !ruby/object:Gem::Version
|
128
|
-
hash: 3
|
129
|
-
segments:
|
130
|
-
- 0
|
131
119
|
version: "0"
|
132
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
121
|
none: false
|
134
122
|
requirements:
|
135
123
|
- - ">="
|
136
124
|
- !ruby/object:Gem::Version
|
137
|
-
hash: 3
|
138
|
-
segments:
|
139
|
-
- 0
|
140
125
|
version: "0"
|
141
126
|
requirements: []
|
142
127
|
|
143
128
|
rubyforge_project: childprocess
|
144
|
-
rubygems_version: 1.
|
129
|
+
rubygems_version: 1.8.5
|
145
130
|
signing_key:
|
146
131
|
specification_version: 3
|
147
132
|
summary: This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.
|