Skip to content

Commit 476ee69

Browse files
authored
Only redirect stderr if ExecStdError is not null (#1377)
1 parent fb0723e commit 476ee69

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public static string RenewAzureToken(string tenantId, string clientId, string ap
494494
throw new KubeConfigException("Refresh not supported.");
495495
}
496496

497-
public static Process CreateRunnableExternalProcess(ExternalExecution config)
497+
public static Process CreateRunnableExternalProcess(ExternalExecution config, EventHandler<DataReceivedEventArgs> captureStdError = null)
498498
{
499499
if (config == null)
500500
{
@@ -535,7 +535,7 @@ public static Process CreateRunnableExternalProcess(ExternalExecution config)
535535
}
536536

537537
process.StartInfo.RedirectStandardOutput = true;
538-
process.StartInfo.RedirectStandardError = true;
538+
process.StartInfo.RedirectStandardError = captureStdError != null;
539539
process.StartInfo.UseShellExecute = false;
540540
process.StartInfo.CreateNoWindow = true;
541541

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

563-
var process = CreateRunnableExternalProcess(config);
563+
var captureStdError = ExecStdError;
564+
var process = CreateRunnableExternalProcess(config, captureStdError);
564565

565566
try
566567
{
567568
process.Start();
568-
if (ExecStdError != null)
569+
if (captureStdError != null)
569570
{
570-
process.ErrorDataReceived += (s, e) => ExecStdError.Invoke(s, e);
571+
process.ErrorDataReceived += captureStdError.Invoke;
571572
process.BeginErrorReadLine();
572573
}
573574
}

0 commit comments

Comments
 (0)