execute 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmd.rb +35 -31
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28113ced8b010d381572d185379b3bf300d7007
4
- data.tar.gz: 0203575907f47275bc2d26627ed8c13b41f6120b
3
+ metadata.gz: ad3b97e193c7184c2f7a99a50a75fe11f165119e
4
+ data.tar.gz: 53c7970e467545d6c281e3255accd04bfc4cab40
5
5
  SHA512:
6
- metadata.gz: d6c48031159ece03e145a8cb034159f917a66b4d7c2577551f99ae78bf8dbd2231ba0e79619e552c9c329072f0511127f5103cc51dd3783291509e36cde40c37
7
- data.tar.gz: 459789548b0776501b03faa5845697231059e45825165391c5f10f160f5cb74f5a5a74b45c74a523d8dfea520fc1aedffb8ce2670dcfb6c8f578a2791bbac57e
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
- # 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(cmd) { windows_command(self, cmd) }
32
- # end
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
- {:output => stdout,:error => stderr}.each do |key, stream|
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
- match = cmd.match(/\"(?<path>.+\.exe)/i)
106
- return if(match.nil?)
98
+ def wait_on_spawned_process(hash, cmd)
99
+ yield
100
+ post_execute = Sys::ProcTable.ps
107
101
 
108
- exe = match[:path]
109
- exe = File.basename(exe)
110
- #puts "Exe: #{exe}"
102
+ child_processes = []
103
+ post_execute.each { |ps| child_processes << ps.pid if(ps.include?(hash[:pid])) }
111
104
 
112
- msiexe_pid = 0
113
- post_execute = Sys::ProcTable.ps
114
- post_execute.each do |ps|
115
- msiexe_pid = ps.pid if((ps.name.downcase == exe.downcase) && pre_pids.index(ps.pid).nil?)
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
- if(msiexe_pid != 0)
119
- loop do
120
- s = Sys::ProcTable.ps(msiexe_pid)
121
- break if(s.nil?)
122
- sleep(1)
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
- end
125
- end
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.24
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-28 00:00:00.000000000 Z
11
+ date: 2015-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler