simple_process_runner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/simple_process_runner.rb +38 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab2cdd5f65d2d38d327d5b840012fdabd3b4626e
|
4
|
+
data.tar.gz: 1b84dd46f61996e5f396a9934ba96d2a6c6d3f44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fda8f849698535fec719c02a6849e19062a5a9f7dad8dabde0b2ff3a76cb2b67709e2ac4e03b067407c4fb7b835223eb4a8a34610697fff76a932e34482bb95
|
7
|
+
data.tar.gz: f9677efdb6a501612770975f92027f721f6922174e9b95d63112e0147b16064c789cf7c388ccd0ef68e9ab07086d737c66d0e07dff58fefc3ddc578cab6c52a6
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
class SimpleProcessRunner
|
4
|
+
def self.run_process(cmd_array, data=nil)
|
5
|
+
simple_process = SimpleProcess.new(cmd_array, data)
|
6
|
+
|
7
|
+
return simple_process
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class SimpleProcess
|
12
|
+
def initialize(cmd_array, data=nil)
|
13
|
+
stdin, stdout, stderr, @wait_thr = Open3.popen3(*cmd_array)
|
14
|
+
|
15
|
+
@stdout_thread = Thread.new do
|
16
|
+
Thread.current[:result] = stdout.read
|
17
|
+
stdout.close
|
18
|
+
end
|
19
|
+
|
20
|
+
@stderr_thread = Thread.new do
|
21
|
+
Thread.current[:result] = stderr.read
|
22
|
+
stderr.close
|
23
|
+
end
|
24
|
+
|
25
|
+
Thread.new do
|
26
|
+
stdin.write data if data
|
27
|
+
stdin.close
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def wait
|
32
|
+
exit_code = @wait_thr.value.exitstatus
|
33
|
+
output = @stdout_thread.join[:result]
|
34
|
+
error = @stderr_thread.join[:result]
|
35
|
+
|
36
|
+
return exit_code, output, error
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_process_runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Sykes
|
8
|
+
- Nick Doyle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Allows the user to run processess ansychronously and without a shell,
|
15
|
+
optionally the user can wait for them to complete and return data
|
16
|
+
email: brettcsykes@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/simple_process_runner.rb
|
22
|
+
homepage: https://github.com/bretts/simple_process_runner
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.6.7
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Run shell-less processes ansychronously and optionally wait for them to complete
|
46
|
+
test_files: []
|