diff --git a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs index 6c2c7be4d..9661679a8 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs @@ -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 captureStdError = null) { if (config == null) { @@ -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; @@ -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(); } }