execute 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cmd.rb +59 -21
- metadata +16 -3
- data/lib/IOAdapter.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b28878be7892166a674abab1f00bb7919049a43
|
4
|
+
data.tar.gz: 15d599ee83edd61212cb3e29a79d785d598978f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36578b7eb8ee3e861eba87a16ff8c322fb6d3d644bec4153c75aca919f5a6b7f82677e5527f85f3387531396860c28236a59c255afd78f44b7098afbf8536149
|
7
|
+
data.tar.gz: 6948248f5a73c703543fec42dfdebea68070e280893d3fb19e3f8c5df4509e782d2be043d63fe7f5ae54313bd8d42bf890bd3c1eec9550e29cb69f3fa3bc8412
|
data/lib/cmd.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'sys/proctable'
|
3
|
-
require_relative 'IOAdapter.rb'
|
4
3
|
|
5
4
|
class CMD < Hash
|
6
5
|
private
|
@@ -21,45 +20,84 @@ class CMD < Hash
|
|
21
20
|
def self.default_options(hash)
|
22
21
|
hash.each { |key, value| @@default_options[key] = value}
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
def execute
|
26
|
-
|
27
|
-
|
25
|
+
windows_command(self, self[:command])
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_as(username)
|
29
|
+
raise "Unsported on operating system #{RbConfig::CONFIG["host_os"]}" unless(RbConfig::CONFIG["host_os"].include?("mingw"))
|
30
|
+
cmd = "runas /noprofile /savecred /user:#{username} \"#{self[:command]}\""
|
31
|
+
wait_on_spawned_process(cmd) { windows_command(self, cmd) }
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def windows_command(hash, cmd)
|
28
36
|
begin
|
29
|
-
puts
|
37
|
+
puts cmd if(hash[:echo_command] || hash[:debug])
|
30
38
|
|
31
39
|
output = {output: [], error: [] }
|
32
|
-
Open3.popen3(
|
40
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
33
41
|
{:output => stdout,:error => stderr}.each do |key, stream|
|
34
42
|
Thread.new do
|
35
43
|
until(raw_line = stream.gets).nil? do
|
36
44
|
output[key] << raw_line
|
37
|
-
puts raw_line if(
|
45
|
+
puts raw_line if(hash[:echo_output])
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
wait_thr.join
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
hash[:output] = output[:output].join
|
51
|
+
hash[:error] = output[:error].join
|
52
|
+
hash[:exit_code] = wait_thr.value.to_i
|
45
53
|
end
|
46
54
|
rescue Exception => e
|
47
|
-
|
48
|
-
|
55
|
+
hash[:error] = "#{hash[:error]}\nException: #{e.to_s}"
|
56
|
+
hash[:exit_code]=1 unless(hash[:exit_code].nil? || (hash[:exit_code] == 0))
|
49
57
|
end
|
50
58
|
|
51
|
-
if(
|
52
|
-
puts "command: #{
|
53
|
-
puts "output: #{
|
54
|
-
puts "error: #{
|
55
|
-
puts "exit_code: #{
|
59
|
+
if(hash[:debug])
|
60
|
+
puts "command: #{cmd}" if(hash[:quiet])
|
61
|
+
puts "output: #{hash[:output]}"
|
62
|
+
puts "error: #{hash[:error]}"
|
63
|
+
puts "exit_code: #{hash[:exit_code]}"
|
56
64
|
end
|
57
65
|
|
58
|
-
if((
|
59
|
-
exception_text = "Exit code: #{
|
60
|
-
exception_text = "#{exception_text}\n#{
|
61
|
-
exception_text = "#{exception_text}\n#{
|
66
|
+
if((hash[:exit_code] != 0) && !hash[:ignore_exit_code])
|
67
|
+
exception_text = "Exit code: #{hash[:exit_code]}"
|
68
|
+
exception_text = "#{exception_text}\n#{hash[:error]}"
|
69
|
+
exception_text = "#{exception_text}\n#{hash[:output]}" if(hash[:error].empty?)
|
62
70
|
raise exception_text
|
63
71
|
end
|
64
72
|
end
|
73
|
+
|
74
|
+
def wait_on_spawned_process(cmd)
|
75
|
+
pre_execute = Sys::ProcTable.ps
|
76
|
+
|
77
|
+
pre_pids = []
|
78
|
+
pre_execute.each { |ps| pre_pids << ps.pid }
|
79
|
+
|
80
|
+
yield
|
81
|
+
|
82
|
+
match = cmd.match(/\\(?<path>.+\.exe)/i)
|
83
|
+
return if(match.nil?)
|
84
|
+
|
85
|
+
exe = match.named_captures['path']
|
86
|
+
exe = File.basename(exe)
|
87
|
+
#puts "Exe: #{exe}"
|
88
|
+
|
89
|
+
msiexe_pid = 0
|
90
|
+
post_execute = Sys::ProcTable.ps
|
91
|
+
post_execute.each do |ps|
|
92
|
+
msiexe_pid = ps.pid if((ps.name.downcase == exe.downcase) && pre_pids.index(ps.pid).nil?)
|
93
|
+
end
|
94
|
+
|
95
|
+
if(msiexe_pid != 0)
|
96
|
+
loop do
|
97
|
+
s = Sys::ProcTable.ps(msiexe_pid)
|
98
|
+
break if(s.nil?)
|
99
|
+
sleep(1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
65
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sys-proctable
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.8
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.8
|
69
83
|
description: Class wrapper for system commands
|
70
84
|
email: KCCKSMarshall@gmail.com
|
71
85
|
executables: []
|
@@ -74,7 +88,6 @@ extra_rdoc_files: []
|
|
74
88
|
files:
|
75
89
|
- LICENSE
|
76
90
|
- README.md
|
77
|
-
- lib/IOAdapter.rb
|
78
91
|
- lib/cmd.rb
|
79
92
|
homepage: http://rubygems.org/gems/execute
|
80
93
|
licenses:
|
data/lib/IOAdapter.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
require 'tempfile'
|
3
|
-
class IOAdapter < DelegateClass(IO)
|
4
|
-
attr_accessor :output_buffer
|
5
|
-
def initialize(io)
|
6
|
-
__setobj__(io)
|
7
|
-
@output_buffer = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def write(string)
|
11
|
-
@output_buffer << string
|
12
|
-
self.__getobj__.write(string)
|
13
|
-
end
|
14
|
-
end
|