fix: accessing Standard* of a Process requires manually disposing them afterwards (#10125)

This commit is contained in:
Claus Vium
2023-08-20 20:06:57 +02:00
committed by GitHub
parent 260680d727
commit 956e3dab43
6 changed files with 56 additions and 48 deletions

View File

@@ -553,7 +553,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
private string GetProcessOutput(string path, string arguments, bool readStdErr, string? testKey)
{
using (var process = new Process()
var redirectStandardIn = !string.IsNullOrEmpty(testKey);
using (var process = new Process
{
StartInfo = new ProcessStartInfo(path, arguments)
{
@@ -561,7 +562,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false,
RedirectStandardInput = !string.IsNullOrEmpty(testKey),
RedirectStandardInput = redirectStandardIn,
RedirectStandardOutput = true,
RedirectStandardError = true
}
@@ -571,12 +572,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
process.Start();
if (!string.IsNullOrEmpty(testKey))
if (redirectStandardIn)
{
process.StandardInput.Write(testKey);
using var writer = process.StandardInput;
writer.Write(testKey);
}
return readStdErr ? process.StandardError.ReadToEnd() : process.StandardOutput.ReadToEnd();
using var reader = readStdErr ? process.StandardError : process.StandardOutput;
return reader.ReadToEnd();
}
}
}