open5 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -0
- data/lib/open5.rb +24 -0
- metadata +56 -0
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# open5
|
2
|
+
|
3
|
+
gem install open5
|
4
|
+
|
5
|
+
and
|
6
|
+
|
7
|
+
require 'open5'
|
8
|
+
open5('command', 'opt') {|i, o, e, t|
|
9
|
+
i.puts 'input!'
|
10
|
+
p o.gets
|
11
|
+
Process.kill 'KILL', t.pid
|
12
|
+
}
|
13
|
+
|
14
|
+
or
|
15
|
+
|
16
|
+
require 'open5'
|
17
|
+
i, o, e, t = open5('command', 'opt')
|
18
|
+
|
19
|
+
## Why open5?
|
20
|
+
|
21
|
+
* `open3` doesn't give the pid on ruby 1.8.
|
22
|
+
* `open4` has different interface to `open3` on ruby 1.9.
|
23
|
+
* `tasks` doesn't work on Windows because it uses `fork`.
|
24
|
+
|
25
|
+
`open5` works both on ruby 1.8 and 1.9, and supports Windows! (Though I've never tested it on Windows yet.)
|
26
|
+
|
27
|
+
## Dependency
|
28
|
+
|
29
|
+
* `open4`
|
30
|
+
|
31
|
+
## Author
|
32
|
+
|
33
|
+
Tatsuhiro Ujihisa
|
data/lib/open5.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
if RUBY_VERSION < '1.9'
|
2
|
+
#abort "Windows doesn't support open5 on ruby 1.8" if /ms/ =~ RUBY_PLATFORM
|
3
|
+
require 'rubygems'
|
4
|
+
require 'open4'
|
5
|
+
def open5(*cmd, &block)
|
6
|
+
if block_given?
|
7
|
+
Open4.popen4(*cmd) {|pid, i, o, e|
|
8
|
+
t = {:pid => pid}
|
9
|
+
def t.pid; self[:pid]; end
|
10
|
+
block.call i, o, e, t
|
11
|
+
}
|
12
|
+
else
|
13
|
+
pid, i, o, e = Open4.popen4(*cmd)
|
14
|
+
t = {:pid => pid}
|
15
|
+
def t.pid; self[:pid]; end
|
16
|
+
[i, o, e, t]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
else
|
20
|
+
require 'open3'
|
21
|
+
def open5(*cmd, &block)
|
22
|
+
Open3.popen3(*cmd, &block)
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ujihisa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-04 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "open5(cmd, *option) #=> stdin, stdout, stderr, thread"
|
17
|
+
email: ujihisa at gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.md
|
24
|
+
files:
|
25
|
+
- lib/open5.rb
|
26
|
+
- README.md
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: https://github.com/ujihisa/open5
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: "open5(cmd, *option) #=> stdin, stdout, stderr, thread"
|
55
|
+
test_files: []
|
56
|
+
|