From 547dbf335eb715cd4655083afbd4078cada7c1aa Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Sat, 1 Aug 2015 01:12:50 -0700 Subject: [PATCH 1/2] silence the progress stream otherwise any output to this stream will leak to stderr. see https://connect.microsoft.com/PowerShell/feedback/details/927384/progress-stream-being-sent-to-stderr-in-winrm-responses --- lib/winrm-fs/core/command_executor.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/winrm-fs/core/command_executor.rb b/lib/winrm-fs/core/command_executor.rb index 551ceb8..7155ec0 100644 --- a/lib/winrm-fs/core/command_executor.rb +++ b/lib/winrm-fs/core/command_executor.rb @@ -35,7 +35,7 @@ def close def run_powershell(script) assert_shell_is_open - run_cmd('powershell', ['-encodedCommand', encode_script(script)]) + run_cmd('powershell', ['-encodedCommand', encode_script(safe_script(script))]) end def run_cmd(command, arguments = []) @@ -63,6 +63,11 @@ def encode_script(script) encoded_script = script.encode('UTF-16LE', 'UTF-8') Base64.strict_encode64(encoded_script) end + + # suppress the progress stream from leaking to stderr + def safe_script(script) + "$ProgressPreference='SilentlyContinue';" + script + end end end end From 2cf8460846916c99ddeef34495ec8f5d664fdcc1 Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Sat, 1 Aug 2015 01:14:04 -0700 Subject: [PATCH 2/2] using write-output instead of write-host since PS v5 now leaks the host stream to stderr --- lib/winrm-fs/scripts/checksum.ps1.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/winrm-fs/scripts/checksum.ps1.erb b/lib/winrm-fs/scripts/checksum.ps1.erb index 87384e8..ecb2dc4 100644 --- a/lib/winrm-fs/scripts/checksum.ps1.erb +++ b/lib/winrm-fs/scripts/checksum.ps1.erb @@ -9,5 +9,5 @@ if (Test-Path $path -PathType Leaf) { $md5 = $md5.Replace("-","").ToLower() $file.Close() - Write-Host $md5 + Write-Output $md5 }