From b6b67217224453d14b671a390d9a62baaef78f2a Mon Sep 17 00:00:00 2001 From: IharKotau Date: Wed, 28 Jul 2021 13:29:39 +0300 Subject: [PATCH] added def self.execute_ps_command --- lib/instance_agent/platform/windows_util.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/instance_agent/platform/windows_util.rb b/lib/instance_agent/platform/windows_util.rb index 6238b9a4..f3684535 100644 --- a/lib/instance_agent/platform/windows_util.rb +++ b/lib/instance_agent/platform/windows_util.rb @@ -74,7 +74,7 @@ def self.delete_dirs_command(dirs_to_delete) private def self.delete_folder (dir) if dir != nil && dir != "/" - output = `rd /s /q "#{dir}" 2>&1` + output = execute_ps_command("Remove-Item #{dir} -Recurse -Force 2>&1") exit_status = $?.exitstatus log(:debug, "Command status: #{$?}") log(:debug, "Command output: #{output}") @@ -88,6 +88,12 @@ def self.delete_folder (dir) end end + private + def self.execute_ps_command(ps_command) + exec_command = 'powershell.exe -ExecutionPolicy Bypass -Command ' + ps_command + exec_command + end + private def self.execute_zip_command(cmd) log(:debug, "Executing #{cmd}")