diff --git a/source/Calamari.Common/Features/Processes/CommandLineInvocation.cs b/source/Calamari.Common/Features/Processes/CommandLineInvocation.cs
index b46196025c..22e36bfd10 100644
--- a/source/Calamari.Common/Features/Processes/CommandLineInvocation.cs
+++ b/source/Calamari.Common/Features/Processes/CommandLineInvocation.cs
@@ -43,6 +43,11 @@ public CommandLineInvocation(string executable, params string[] arguments)
///
public bool OutputAsVerbose { get; set; }
+ ///
+ /// Use UTF-8 encoding for standard output and error streams.
+ ///
+ public bool UseUTF8 { get; set; }
+
///
/// Add a non-standard output destination for the execution output
///
diff --git a/source/Calamari.Common/Features/Processes/CommandLineRunner.cs b/source/Calamari.Common/Features/Processes/CommandLineRunner.cs
index 46eec48982..7b49e4caf9 100644
--- a/source/Calamari.Common/Features/Processes/CommandLineRunner.cs
+++ b/source/Calamari.Common/Features/Processes/CommandLineRunner.cs
@@ -34,7 +34,8 @@ public CommandResult Execute(CommandLineInvocation invocation)
invocation.UserName,
invocation.Password,
commandOutput.WriteInfo,
- commandOutput.WriteError);
+ commandOutput.WriteError,
+ invocation.UseUTF8);
return new CommandResult(
invocation.ToString(),
diff --git a/source/Calamari.Common/Features/Processes/SilentProcessRunner.cs b/source/Calamari.Common/Features/Processes/SilentProcessRunner.cs
index 7a735430af..61eb5cae6a 100644
--- a/source/Calamari.Common/Features/Processes/SilentProcessRunner.cs
+++ b/source/Calamari.Common/Features/Processes/SilentProcessRunner.cs
@@ -51,7 +51,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
null,
null,
output,
- error);
+ error,
+ false);
}
public static SilentProcessRunnerResult ExecuteCommand(
@@ -69,7 +70,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
null,
null,
output,
- error);
+ error,
+ false);
}
public static SilentProcessRunnerResult ExecuteCommand(
@@ -80,7 +82,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
string? userName,
SecureString? password,
Action output,
- Action error)
+ Action error,
+ bool useUtf8Encoding)
{
try
{
@@ -93,8 +96,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
- process.StartInfo.StandardOutputEncoding = oemEncoding;
- process.StartInfo.StandardErrorEncoding = oemEncoding;
+ process.StartInfo.StandardOutputEncoding = useUtf8Encoding ? Encoding.UTF8 : oemEncoding;
+ process.StartInfo.StandardErrorEncoding = useUtf8Encoding ? Encoding.UTF8 : oemEncoding;
if (environmentVars != null)
foreach (var environmentVar in environmentVars.Keys)
diff --git a/source/Calamari.Common/Features/Scripting/DotnetScript/DotnetScriptExecutor.cs b/source/Calamari.Common/Features/Scripting/DotnetScript/DotnetScriptExecutor.cs
index b581fdab59..1fcb2c8f41 100644
--- a/source/Calamari.Common/Features/Scripting/DotnetScript/DotnetScriptExecutor.cs
+++ b/source/Calamari.Common/Features/Scripting/DotnetScript/DotnetScriptExecutor.cs
@@ -41,6 +41,7 @@ protected override IEnumerable PrepareExecution(Script script,
cli.EnvironmentVars = environmentVars;
cli.WorkingDirectory = workingDirectory;
cli.Isolate = !bypassDotnetScriptIsolation;
+ cli.UseUTF8 = true; /* TODO Make UTF-8 encoding an opt-out setting */
cli.AdditionalInvocationOutputSink = outputSink;
diff --git a/source/Calamari.Common/Features/Scripting/WindowsPowerShell/PowerShellScriptExecutor.cs b/source/Calamari.Common/Features/Scripting/WindowsPowerShell/PowerShellScriptExecutor.cs
index 3d51405afd..f27e487939 100644
--- a/source/Calamari.Common/Features/Scripting/WindowsPowerShell/PowerShellScriptExecutor.cs
+++ b/source/Calamari.Common/Features/Scripting/WindowsPowerShell/PowerShellScriptExecutor.cs
@@ -51,7 +51,8 @@ protected override IEnumerable PrepareExecution(Script script,
EnvironmentVars = effectiveEnvironmentVars,
WorkingDirectory = Path.GetDirectoryName(script.File),
UserName = powerShellBootstrapper.AllowImpersonation() ? variables.Get(PowerShellVariables.UserName) : null,
- Password = powerShellBootstrapper.AllowImpersonation() ? ToSecureString(variables.Get(PowerShellVariables.Password)) : null
+ Password = powerShellBootstrapper.AllowImpersonation() ? ToSecureString(variables.Get(PowerShellVariables.Password)) : null,
+ UseUTF8 = true, /* TODO Make UTF-8 encoding an opt-out setting */
};
return new[]