summaryrefslogtreecommitdiff
path: root/lib/chef/provider/powershell_script.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/provider/powershell_script.rb')
-rw-r--r--lib/chef/provider/powershell_script.rb26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb
index 2b7c384246..80d20670ec 100644
--- a/lib/chef/provider/powershell_script.rb
+++ b/lib/chef/provider/powershell_script.rb
@@ -31,21 +31,32 @@ class Chef
super()
end
- def command
- # Powershell.exe is always in "v1.0" folder (for backwards compatibility)
- interpreter_path = Chef::Util::PathHelper.join(basepath, "WindowsPowerShell", "v1.0", interpreter)
+ # Set InputFormat to None as PowerShell will hang if STDIN is redirected
+ # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
+ DEFAULT_FLAGS = "-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None"
+ def command
# Must use -File rather than -Command to launch the script
# file created by the base class that contains the script
# code -- otherwise, powershell.exe does not propagate the
# error status of a failed Windows process that ran at the
# end of the script, it gets changed to '1'.
#
- "\"#{interpreter_path}\" #{new_resource.flags} -File \"#{script_file_path}\""
+ [
+ %Q{"#{interpreter_path}"},
+ DEFAULT_FLAGS,
+ new_resource.flags,
+ %Q{-File "#{script_file_path}"},
+ ].join(" ")
end
protected
+ def interpreter_path
+ # Powershell.exe is always in "v1.0" folder (for backwards compatibility)
+ Chef::Util::PathHelper.join(basepath, "WindowsPowerShell", "v1.0", interpreter)
+ end
+
def code
code = wrapper_script
logger.trace("powershell_script provider called with script code:\n\n#{new_resource.code}\n")
@@ -71,7 +82,12 @@ class Chef
# written to the file system at this point, which is required since
# the intent is to execute the code just written to it.
user_script_file.close
- validation_command = "\"#{interpreter}\" #{new_resource.flags} -Command \". '#{user_script_file.path}'\""
+ validation_command = [
+ %Q{"#{interpreter_path}"},
+ DEFAULT_FLAGS,
+ new_resource.flags,
+ %Q{-Command ". '#{user_script_file.path}'"},
+ ].join(" ")
# Note that other script providers like bash allow syntax errors
# to be suppressed by setting 'returns' to a value that the