shexecutor 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -5
- data/lib/shexecutor/version.rb +1 -1
- data/lib/shexecutor.rb +32 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dbf10b351afc189794bb119a82b063c7c68bb90
|
4
|
+
data.tar.gz: 52b64aa38d6c94ca2bd678a1a6bceb854fd5acbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8104a387512908469f7bf9d9887900c848905956e4a03fd75e6a69d30218922b2e67a49b82ff0c4353b5dd89fb4b0d1e36f23d9d9c1a6c3878378aede0caba2a
|
7
|
+
data.tar.gz: 3185e4df180990e334bb2240cca83dc01423de2e40c18ad546c7ff6b4e51dfb4614f80d7511bc7607c5e0b21cdbc6fe3bebafb69363197f3f556ff1317a1227b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ SHExecutor is a convenience wrapper for executing shell commands from with-in a
|
|
5
5
|
## It supports:
|
6
6
|
- blocking indefinitely, on exit you can get status, stdout and stderr
|
7
7
|
- blocking with timeout, on exit you can get status, stdout, stderr, timeout exception (then output streams are not available)
|
8
|
-
- non-blocking, then you get
|
8
|
+
- non-blocking, then you get handles to the output streams and the status of the forked process
|
9
9
|
- replacement, then you get a replaced process and none of the above
|
10
10
|
- redirecting of stderr and stdout, separately, to file, with the option to overwrite or append
|
11
11
|
|
@@ -65,12 +65,12 @@ Or install it yourself as:
|
|
65
65
|
|
66
66
|
```
|
67
67
|
iut = SHExecutor::Executor.new({:wait_for_completion => true, :application_path => "/bin/echo", :params => ["hello world"]})
|
68
|
-
iut.execute
|
68
|
+
result = iut.execute
|
69
69
|
iut.flush
|
70
70
|
puts "After execution status is: #{iut.status}"
|
71
71
|
# "no longer executing"
|
72
72
|
puts "out: #{iut.stdout} err: #{iut.stderr}"
|
73
|
-
puts "#{
|
73
|
+
puts "#{result.pid} success? #{result.success?} with code #{result.exitstatus}"
|
74
74
|
puts "For more see: #{iut.result.methods}"
|
75
75
|
```
|
76
76
|
|
@@ -78,7 +78,7 @@ puts "For more see: #{iut.result.methods}"
|
|
78
78
|
|
79
79
|
```
|
80
80
|
iut = SHExecutor::Executor.new({:timeout => 1, :wait_for_completion => true, :application_path => "/bin/sleep", :params => ["2"]})
|
81
|
-
iut.execute
|
81
|
+
result = iut.execute
|
82
82
|
# Timeout::Error gets raised. The spawned process continues and needs to be managed separately if required.
|
83
83
|
```
|
84
84
|
|
@@ -86,8 +86,9 @@ iut.execute
|
|
86
86
|
|
87
87
|
```
|
88
88
|
iut = SHExecutor::Executor.new({:wait_for_completion => false, :application_path => "/bin/sleep", :params => ["1"]})
|
89
|
-
iut.execute
|
89
|
+
stdout, stderr, thr = iut.execute
|
90
90
|
puts "Status: #{iut.status}"
|
91
|
+
puts "PID: #{thr.pid}"
|
91
92
|
# "run" or "sleep"
|
92
93
|
sleep 2
|
93
94
|
puts "Status: #{iut.status}"
|
data/lib/shexecutor/version.rb
CHANGED
data/lib/shexecutor.rb
CHANGED
@@ -19,14 +19,21 @@ module SHExecutor
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class Executor
|
22
|
-
|
22
|
+
public
|
23
|
+
|
23
24
|
attr_accessor :stdout
|
24
25
|
attr_accessor :stderr
|
26
|
+
attr_accessor :options
|
27
|
+
|
28
|
+
private
|
29
|
+
|
25
30
|
attr_accessor :result
|
26
31
|
attr_accessor :pid
|
27
32
|
attr_accessor :data_out
|
28
33
|
attr_accessor :data_err
|
29
34
|
|
35
|
+
public
|
36
|
+
|
30
37
|
def initialize(options = ::SHExecutor::default_options)
|
31
38
|
# set default options
|
32
39
|
@options = ::SHExecutor::default_options.dup
|
@@ -50,10 +57,6 @@ module SHExecutor
|
|
50
57
|
@result.value
|
51
58
|
end
|
52
59
|
|
53
|
-
def possible_injection?(application_path)
|
54
|
-
(@options[:protect_against_injection]) and (@options[:application_path].include?(" ") or @options[:application_path].tainted?)
|
55
|
-
end
|
56
|
-
|
57
60
|
def validate
|
58
61
|
errors = []
|
59
62
|
if (@options[:protect_against_injection]) and (!@options[:application_path].nil? and @options[:application_path].strip != "")
|
@@ -104,8 +107,31 @@ module SHExecutor
|
|
104
107
|
stderr_to_file if (@options[:stderr_path])
|
105
108
|
end
|
106
109
|
|
110
|
+
def execute_blocking(application_path, params = nil)
|
111
|
+
executor = SHExecutor::Executor.new({:wait_for_completion => true, :application_path => application_path, :params => params})
|
112
|
+
result = executor.execute
|
113
|
+
executor.flush
|
114
|
+
return result, executor.stdout, executor.stderr
|
115
|
+
end
|
116
|
+
|
117
|
+
def execute_and_timeout_after(application_path, params = nil, timeout = -1)
|
118
|
+
executor = SHExecutor::Executor.new({:timeout => timeout, :wait_for_completion => true, :application_path => application_path, :params => params})
|
119
|
+
result = executor.execute
|
120
|
+
executor.flush
|
121
|
+
return result, executor.stdout, executor.stderr
|
122
|
+
end
|
123
|
+
|
124
|
+
def execute_non_blocking(application_path, params = nil)
|
125
|
+
executor = SHExecutor::Executor.new({:wait_for_completion => false, :application_path => application_path, :params => params})
|
126
|
+
executor.execute
|
127
|
+
end
|
128
|
+
|
107
129
|
private
|
108
130
|
|
131
|
+
def possible_injection?(application_path)
|
132
|
+
(@options[:protect_against_injection]) and (@options[:application_path].include?(" ") or @options[:application_path].tainted?)
|
133
|
+
end
|
134
|
+
|
109
135
|
def buffer_to_file(buffer, path, append)
|
110
136
|
if not append
|
111
137
|
FileUtils.rm_f(path)
|
@@ -199,6 +225,7 @@ module SHExecutor
|
|
199
225
|
def fork_process
|
200
226
|
validate
|
201
227
|
@stdin_stream, @stdout_stream, @stderr_stream, @result = Open3::popen3(@options[:application_path], *@options[:params])
|
228
|
+
return @result, @stdout_stream, @stderr_stream
|
202
229
|
end
|
203
230
|
|
204
231
|
def should_timeout?
|