Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public CommandLineInvocation(string executable, params string[] arguments)
/// </summary>
public bool OutputAsVerbose { get; set; }

/// <summary>
/// Use UTF-8 encoding for standard output and error streams.
/// </summary>
public bool UseUTF8 { get; set; }

/// <summary>
/// Add a non-standard output destination for the execution output
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 8 additions & 5 deletions source/Calamari.Common/Features/Processes/SilentProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
null,
null,
output,
error);
error,
false);
}

public static SilentProcessRunnerResult ExecuteCommand(
Expand All @@ -69,7 +70,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
null,
null,
output,
error);
error,
false);
}

public static SilentProcessRunnerResult ExecuteCommand(
Expand All @@ -80,7 +82,8 @@ public static SilentProcessRunnerResult ExecuteCommand(
string? userName,
SecureString? password,
Action<string> output,
Action<string> error)
Action<string> error,
bool useUtf8Encoding)
{
try
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected override IEnumerable<ScriptExecution> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected override IEnumerable<ScriptExecution> 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[]
Expand Down