Skip to content

Commit

Permalink
Only redirect stderr if ExecStdError is not null (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
bianyifan committed Aug 30, 2023
1 parent fb0723e commit 476ee69
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public static string RenewAzureToken(string tenantId, string clientId, string ap
throw new KubeConfigException("Refresh not supported.");
}

public static Process CreateRunnableExternalProcess(ExternalExecution config)
public static Process CreateRunnableExternalProcess(ExternalExecution config, EventHandler<DataReceivedEventArgs> captureStdError = null)
{
if (config == null)
{
Expand Down Expand Up @@ -535,7 +535,7 @@ public static Process CreateRunnableExternalProcess(ExternalExecution config)
}

process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardError = captureStdError != null;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

Expand All @@ -560,14 +560,15 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
throw new ArgumentNullException(nameof(config));
}

var process = CreateRunnableExternalProcess(config);
var captureStdError = ExecStdError;
var process = CreateRunnableExternalProcess(config, captureStdError);

try
{
process.Start();
if (ExecStdError != null)
if (captureStdError != null)
{
process.ErrorDataReceived += (s, e) => ExecStdError.Invoke(s, e);
process.ErrorDataReceived += captureStdError.Invoke;
process.BeginErrorReadLine();
}
}
Expand Down

0 comments on commit 476ee69

Please sign in to comment.