execute 0.1.24 → 0.1.25
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 +35 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad3b97e193c7184c2f7a99a50a75fe11f165119e
|
4
|
+
data.tar.gz: 53c7970e467545d6c281e3255accd04bfc4cab40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c80ac5d1c8cec9b7899cf738553855c85f078beb1ef6cae10d571f82b292862239ab7a1bab17b6becafd438ab8ec1b0480f8aa95048dc64ed4085a692b645b0
|
7
|
+
data.tar.gz: 69c17292b94cd09b55171ce098f2d820b7e1153c80cb1a56d1580e86ce1d7066e16603788e4bcb98df0f4b07e8e2682f8d21e527ec65f32ddac504ecb2856e60
|
data/lib/cmd.rb
CHANGED
@@ -25,11 +25,11 @@ class CMD < Hash
|
|
25
25
|
windows_command(self, self[:command])
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def execute_as(username)
|
29
|
+
raise "Unsupported 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(self,cmd) { windows_command(self, cmd) }
|
32
|
+
end
|
33
33
|
|
34
34
|
private
|
35
35
|
def windows_command(hash, cmd)
|
@@ -38,7 +38,8 @@ class CMD < Hash
|
|
38
38
|
|
39
39
|
output = {output: [], error: [] }
|
40
40
|
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
41
|
-
|
41
|
+
hash[:pid] = wait_thr.pid
|
42
|
+
{:output => stdout,:error => stderr}.each do |key, stream|
|
42
43
|
Thread.new do
|
43
44
|
while wait_thr.alive? do
|
44
45
|
if(!(char = stream.getc).nil?)
|
@@ -93,34 +94,37 @@ class CMD < Hash
|
|
93
94
|
raise exception_text
|
94
95
|
end
|
95
96
|
end
|
96
|
-
|
97
|
-
def wait_on_spawned_process(cmd)
|
98
|
-
pre_execute = Sys::ProcTable.ps
|
99
|
-
|
100
|
-
pre_pids = []
|
101
|
-
pre_execute.each { |ps| pre_pids << ps.pid }
|
102
|
-
|
103
|
-
yield
|
104
97
|
|
105
|
-
|
106
|
-
|
98
|
+
def wait_on_spawned_process(hash, cmd)
|
99
|
+
yield
|
100
|
+
post_execute = Sys::ProcTable.ps
|
107
101
|
|
108
|
-
|
109
|
-
|
110
|
-
#puts "Exe: #{exe}"
|
102
|
+
child_processes = []
|
103
|
+
post_execute.each { |ps| child_processes << ps.pid if(ps.include?(hash[:pid])) }
|
111
104
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
105
|
+
trap("INT") do
|
106
|
+
child_processes.each do |pid|
|
107
|
+
s = Sys::ProcTable.ps(pid)
|
108
|
+
begin
|
109
|
+
if(!s.nil?)
|
110
|
+
out_rd,out_wr = IO.pipe
|
111
|
+
err_rd,err_wr = IO.pipe
|
112
|
+
system("taskkill /pid #{pid}", :out => out_wr, :err => err_wr)
|
113
|
+
end
|
114
|
+
rescue Exception => e
|
115
|
+
end
|
116
|
+
end
|
117
|
+
exit
|
116
118
|
end
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
|
120
|
+
loop do
|
121
|
+
all_exited = false
|
122
|
+
child_processes.each do |pid|
|
123
|
+
s = Sys::ProcTable.ps(pid)
|
124
|
+
all_exited = false unless(s.nil?)
|
123
125
|
end
|
124
|
-
|
125
|
-
|
126
|
+
break if(all_exited)
|
127
|
+
sleep(0.2)
|
128
|
+
end
|
129
|
+
end
|
126
130
|
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.25
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|