From 22dc4eb1933d14360e41832c45e29678224dcf68 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Tue, 22 Feb 2022 18:32:32 +0000
Subject: [PATCH] os_win32/update-smart-drivedb.ps1.in: Set console encoding.
 Otherwise redirection to gpg occasionally starts with a BOM.

git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@5329 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/ChangeLog                            | 3 +++
 smartmontools/os_win32/update-smart-drivedb.ps1.in | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog
index ebf04b43c..7df90fe66 100644
--- a/smartmontools/ChangeLog
+++ b/smartmontools/ChangeLog
@@ -2,6 +2,9 @@ $Id$
 
 2022-02-22  Christian Franke  <franke@computer.org>
 
+	os_win32/update-smart-drivedb.ps1.in: Set console encoding.
+	Otherwise redirection to gpg occasionally starts with a BOM.
+
 	os_win32/update-smart-drivedb.ps1.in: Unify path syntax.
 
 	do_release: Update code signing key id.
diff --git a/smartmontools/os_win32/update-smart-drivedb.ps1.in b/smartmontools/os_win32/update-smart-drivedb.ps1.in
index 0d6a8c5f5..15634aadc 100644
--- a/smartmontools/os_win32/update-smart-drivedb.ps1.in
+++ b/smartmontools/os_win32/update-smart-drivedb.ps1.in
@@ -490,11 +490,15 @@ Q/qvYlwkbKOdlahjoHrFlkhADSBaO9N1OZp3OYDjziIujMdt2IPKnmM=
 function run_join_out_err($cmd) # $arg1, $arg2, ...
 {
   $cmdobj = Get-Command -CommandType Application -Name $cmd
+  # Don't prepend $input with BOM
+  $enc = [Console]::InputEncoding
+  [Console]::InputEncoding = [System.Text.UTF8Encoding]::new()
   $ErrorActionPreference = "Continue" # Don't abort command on first stderr output
   $LASTEXITCODE = 42
   # Run command and convert ErrorRecords from stderr to plain Strings
   $($input | & $cmdobj @args 2>&1) | %{ $_.ToString() }
   $ErrorActionPreference = "Stop"
+  [Console]::InputEncoding = $enc
 }
 
 function gpg_verify($ascfile, $file, [ref]$ok)
-- 
GitLab