From cb320a69004734711491ffada27963557e0ee0a4 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 15 Jul 2026 06:17:25 +1000 Subject: [PATCH 1/2] Add net11 Process.TryGetProcessById and silent param on Run/RunAsync - Process.TryGetProcessById(int, out Process?) - add `silent` to the fileName overloads of Process.Run/RunAsync (net11 preview6 inserts it after arguments, before timeout/cancellationToken) --- apiCount.include.md | 2 +- api_list.include.md | 7 ++- assemblySize.include.md | 64 ++++++++++----------- src/Consume/Consume.cs | 11 +++- src/Polyfill/ProcessPolyfill.cs | 61 ++++++++++++++++++-- src/Split/net10.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net461/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net462/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net47/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net471/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net472/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net48/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net481/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net5.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net6.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net7.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net8.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/net9.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netcoreapp2.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netcoreapp2.1/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netcoreapp2.2/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netcoreapp3.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netcoreapp3.1/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netstandard2.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/netstandard2.1/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Split/uap10.0/ProcessPolyfill.cs | 49 ++++++++++++++-- src/Tests/PolyfillTests_Process.cs | 43 +++++++++++++- 27 files changed, 1089 insertions(+), 128 deletions(-) diff --git a/apiCount.include.md b/apiCount.include.md index 0c1cc2ed..162535ab 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1,4 +1,4 @@ -**API count: 1021** +**API count: 1022** ### Per Target Framework diff --git a/api_list.include.md b/api_list.include.md index 762d70f1..e05b0868 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -789,15 +789,18 @@ * `Task<(string StandardOutput, string StandardError)> ReadAllTextAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.readalltextasync?view=net-11.0) * `Task WaitForExitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexitasync?view=net-11.0) * `ProcessExitStatus Run(ProcessStartInfo, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-diagnostics-processstartinfo-system-nullable((system-timespan)))) - * `ProcessExitStatus Run(string, IList?, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-string-system-collections-generic-ilist((system-string))-system-nullable((system-timespan)))) + * `ProcessExitStatus Run(string, IList?, bool, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-string-system-collections-generic-ilist((system-string))-system-boolean-system-nullable((system-timespan)))) + * Note: When silent is true, standard output and error are suppressed by redirecting and discarding them (rather than binding to the null device as on net11); standard input remains connected. * `ProcessTextOutput RunAndCaptureText(ProcessStartInfo, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetext?view=net-11.0#system-diagnostics-process-runandcapturetext(system-diagnostics-processstartinfo-system-nullable((system-timespan)))) * `ProcessTextOutput RunAndCaptureText(string, IList?, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetext?view=net-11.0#system-diagnostics-process-runandcapturetext(system-string-system-collections-generic-ilist((system-string))-system-nullable((system-timespan)))) * `Task RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetextasync?view=net-11.0#system-diagnostics-process-runandcapturetextasync(system-diagnostics-processstartinfo-system-threading-cancellationtoken)) * `Task RunAndCaptureTextAsync(string, IList?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetextasync?view=net-11.0#system-diagnostics-process-runandcapturetextasync(system-string-system-collections-generic-ilist((system-string))-system-threading-cancellationtoken)) * `Task RunAsync(ProcessStartInfo, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-diagnostics-processstartinfo-system-threading-cancellationtoken)) - * `Task RunAsync(string, IList?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-string-system-collections-generic-ilist((system-string))-system-threading-cancellationtoken)) + * `Task RunAsync(string, IList?, bool, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-string-system-collections-generic-ilist((system-string))-system-boolean-system-threading-cancellationtoken)) + * Note: When silent is true, standard output and error are suppressed by redirecting and discarding them (rather than binding to the null device as on net11); standard input remains connected. * `int StartAndForget(ProcessStartInfo)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.startandforget?view=net-11.0#system-diagnostics-process-startandforget(system-diagnostics-processstartinfo)) * `int StartAndForget(string, IList?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.startandforget?view=net-11.0#system-diagnostics-process-startandforget(system-string-system-collections-generic-ilist((system-string)))) + * `bool TryGetProcessById(int, Process?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.trygetprocessbyid?view=net-11.0) #### PropertyInfo diff --git a/assemblySize.include.md b/assemblySize.include.md index 726651d6..951b5b7e 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -3,23 +3,23 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| | netstandard2.0 | 8.0KB | 353.0KB | +345.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 306.5KB | +298.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 351.5KB | +343.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| net462 | 7.0KB | 355.0KB | +348.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netstandard2.1 | 8.5KB | 306.5KB | +298.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net461 | 8.5KB | 351.5KB | +343.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| net462 | 7.0KB | 355.5KB | +348.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | | net47 | 7.0KB | 355.0KB | +348.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 354.0KB | +345.5KB | +8.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 352.5KB | +344.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net48 | 8.5KB | 352.5KB | +344.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net481 | 8.5KB | 352.5KB | +344.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp2.0 | 9.0KB | 330.5KB | +321.5KB | +8.5KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 302.5KB | +293.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp3.1 | 9.5KB | 301.0KB | +291.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net5.0 | 9.5KB | 265.0KB | +255.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 206.5KB | +196.5KB | +9.5KB | +7.0KB | +512bytes | +3.5KB | -| net7.0 | 10.0KB | 169.0KB | +159.0KB | +9.0KB | +5.5KB | +512bytes | +3.5KB | -| net8.0 | 9.5KB | 139.5KB | +130.0KB | +8.0KB | | +512bytes | +3.0KB | +| net471 | 8.5KB | 354.0KB | +345.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| net472 | 8.5KB | 353.0KB | +344.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 353.0KB | +344.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 353.0KB | +344.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 330.5KB | +321.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 303.0KB | +293.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.1 | 9.5KB | 301.0KB | +291.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net5.0 | 9.5KB | 265.0KB | +255.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net6.0 | 10.0KB | 206.5KB | +196.5KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | +| net7.0 | 10.0KB | 169.0KB | +159.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 139.5KB | +130.0KB | +8.5KB | +512bytes | +512bytes | +3.5KB | | net9.0 | 9.5KB | 92.5KB | +83.0KB | +8.5KB | | +512bytes | +3.5KB | | net10.0 | 10.0KB | 70.0KB | +60.0KB | +9.0KB | | +1.0KB | +3.5KB | | net11.0 | 10.0KB | 31.5KB | +21.5KB | +9.0KB | | +512bytes | +3.5KB | @@ -30,23 +30,23 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| | netstandard2.0 | 8.0KB | 516.0KB | +508.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 442.9KB | +434.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 515.6KB | +507.1KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| net462 | 7.0KB | 519.1KB | +512.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netstandard2.1 | 8.5KB | 442.9KB | +434.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net461 | 8.5KB | 515.6KB | +507.1KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| net462 | 7.0KB | 519.6KB | +512.6KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | | net47 | 7.0KB | 518.8KB | +511.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 517.5KB | +509.0KB | +15.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 514.9KB | +506.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net48 | 8.5KB | 514.9KB | +506.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net481 | 8.5KB | 514.9KB | +506.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp2.0 | 9.0KB | 482.9KB | +473.9KB | +16.2KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 433.9KB | +424.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp3.1 | 9.5KB | 432.4KB | +422.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net5.0 | 9.5KB | 378.2KB | +368.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 299.6KB | +289.6KB | +17.2KB | +8.7KB | +1.1KB | +4.2KB | -| net7.0 | 10.0KB | 243.5KB | +233.5KB | +16.6KB | +6.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 198.5KB | +189.0KB | +15.5KB | +299bytes | +1.1KB | +3.7KB | +| net471 | 8.5KB | 517.5KB | +509.0KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| net472 | 8.5KB | 515.4KB | +506.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 515.4KB | +506.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 515.4KB | +506.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 482.9KB | +473.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 434.4KB | +424.9KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.1 | 9.5KB | 432.4KB | +422.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net5.0 | 9.5KB | 378.2KB | +368.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net6.0 | 10.0KB | 299.6KB | +289.6KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | +| net7.0 | 10.0KB | 243.5KB | +233.5KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 198.5KB | +189.0KB | +16.0KB | +811bytes | +1.1KB | +4.2KB | | net9.0 | 9.5KB | 130.4KB | +120.9KB | +16.0KB | | +1.1KB | +4.2KB | | net10.0 | 10.0KB | 99.5KB | +89.5KB | +16.5KB | | +1.6KB | +4.2KB | | net11.0 | 10.0KB | 46.9KB | +36.9KB | +16.5KB | | +1.1KB | +4.2KB | diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index 1495f0f6..bc9d7daa 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -1361,7 +1361,9 @@ async Task Process_Methods() ProcessExitStatus status = Process.Run("notexists"); status = Process.Run("notexists", new[] { "a", "b" }); - status = Process.Run("notexists", new[] { "a", "b" }, TimeSpan.FromSeconds(1)); + status = Process.Run("notexists", new[] { "a", "b" }, silent: true); + status = Process.Run("notexists", new[] { "a", "b" }, true, TimeSpan.FromSeconds(1)); + status = Process.Run("notexists", new[] { "a", "b" }, timeout: TimeSpan.FromSeconds(1)); status = Process.Run(new ProcessStartInfo("notexists")); status = Process.Run(new ProcessStartInfo("notexists"), TimeSpan.FromSeconds(1)); _ = status.Canceled; @@ -1370,7 +1372,9 @@ async Task Process_Methods() status = await Process.RunAsync("notexists"); status = await Process.RunAsync("notexists", new[] { "a", "b" }); - status = await Process.RunAsync("notexists", new[] { "a", "b" }, CancellationToken.None); + status = await Process.RunAsync("notexists", new[] { "a", "b" }, silent: true); + status = await Process.RunAsync("notexists", new[] { "a", "b" }, true, CancellationToken.None); + status = await Process.RunAsync("notexists", new[] { "a", "b" }, cancellationToken: CancellationToken.None); status = await Process.RunAsync(new ProcessStartInfo("notexists")); status = await Process.RunAsync(new ProcessStartInfo("notexists"), CancellationToken.None); @@ -1392,6 +1396,9 @@ async Task Process_Methods() pid = Process.StartAndForget("notexists", new[] { "a", "b" }); pid = Process.StartAndForget(new ProcessStartInfo("notexists")); + _ = Process.TryGetProcessById(1, out Process? foundProcess); + _ = foundProcess; + ProcessOutputLine outputLine = new("text", standardError: false); _ = outputLine.Content; _ = outputLine.StandardError; diff --git a/src/Polyfill/ProcessPolyfill.cs b/src/Polyfill/ProcessPolyfill.cs index ef79385f..eaed289a 100644 --- a/src/Polyfill/ProcessPolyfill.cs +++ b/src/Polyfill/ProcessPolyfill.cs @@ -5,6 +5,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -30,12 +31,20 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou /// /// Starts the process described by and , waits for it to exit, and returns the exit status. /// - //Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-string-system-collections-generic-ilist((system-string))-system-nullable((system-timespan))) + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-string-system-collections-generic-ilist((system-string))-system-boolean-system-nullable((system-timespan))) + //Note: When silent is true, standard output and error are suppressed by redirecting and discarding them (rather than binding to the null device as on net11); standard input remains connected. [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. @@ -70,12 +79,20 @@ public static async Task RunAsync(ProcessStartInfo startInfo, /// /// Asynchronously starts the process described by and , waits for it to exit, and returns the exit status. /// - //Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-string-system-collections-generic-ilist((system-string))-system-threading-cancellationtoken) + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-string-system-collections-generic-ilist((system-string))-system-boolean-system-threading-cancellationtoken) + //Note: When silent is true, standard output and error are suppressed by redirecting and discarding them (rather than binding to the null device as on net11); standard input remains connected. [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. @@ -180,6 +197,38 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.trygetprocessbyid?view=net-11.0 + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) diff --git a/src/Split/net10.0/ProcessPolyfill.cs b/src/Split/net10.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net10.0/ProcessPolyfill.cs +++ b/src/Split/net10.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net461/ProcessPolyfill.cs b/src/Split/net461/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net461/ProcessPolyfill.cs +++ b/src/Split/net461/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net462/ProcessPolyfill.cs b/src/Split/net462/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net462/ProcessPolyfill.cs +++ b/src/Split/net462/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net47/ProcessPolyfill.cs b/src/Split/net47/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net47/ProcessPolyfill.cs +++ b/src/Split/net47/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net471/ProcessPolyfill.cs b/src/Split/net471/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net471/ProcessPolyfill.cs +++ b/src/Split/net471/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net472/ProcessPolyfill.cs b/src/Split/net472/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net472/ProcessPolyfill.cs +++ b/src/Split/net472/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net48/ProcessPolyfill.cs b/src/Split/net48/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net48/ProcessPolyfill.cs +++ b/src/Split/net48/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net481/ProcessPolyfill.cs b/src/Split/net481/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net481/ProcessPolyfill.cs +++ b/src/Split/net481/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net5.0/ProcessPolyfill.cs b/src/Split/net5.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net5.0/ProcessPolyfill.cs +++ b/src/Split/net5.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net6.0/ProcessPolyfill.cs b/src/Split/net6.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net6.0/ProcessPolyfill.cs +++ b/src/Split/net6.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net7.0/ProcessPolyfill.cs b/src/Split/net7.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net7.0/ProcessPolyfill.cs +++ b/src/Split/net7.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net8.0/ProcessPolyfill.cs b/src/Split/net8.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net8.0/ProcessPolyfill.cs +++ b/src/Split/net8.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/net9.0/ProcessPolyfill.cs b/src/Split/net9.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/net9.0/ProcessPolyfill.cs +++ b/src/Split/net9.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netcoreapp2.0/ProcessPolyfill.cs b/src/Split/netcoreapp2.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netcoreapp2.0/ProcessPolyfill.cs +++ b/src/Split/netcoreapp2.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netcoreapp2.1/ProcessPolyfill.cs b/src/Split/netcoreapp2.1/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netcoreapp2.1/ProcessPolyfill.cs +++ b/src/Split/netcoreapp2.1/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netcoreapp2.2/ProcessPolyfill.cs b/src/Split/netcoreapp2.2/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netcoreapp2.2/ProcessPolyfill.cs +++ b/src/Split/netcoreapp2.2/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netcoreapp3.0/ProcessPolyfill.cs b/src/Split/netcoreapp3.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netcoreapp3.0/ProcessPolyfill.cs +++ b/src/Split/netcoreapp3.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netcoreapp3.1/ProcessPolyfill.cs b/src/Split/netcoreapp3.1/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netcoreapp3.1/ProcessPolyfill.cs +++ b/src/Split/netcoreapp3.1/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netstandard2.0/ProcessPolyfill.cs b/src/Split/netstandard2.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netstandard2.0/ProcessPolyfill.cs +++ b/src/Split/netstandard2.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/netstandard2.1/ProcessPolyfill.cs b/src/Split/netstandard2.1/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/netstandard2.1/ProcessPolyfill.cs +++ b/src/Split/netstandard2.1/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Split/uap10.0/ProcessPolyfill.cs b/src/Split/uap10.0/ProcessPolyfill.cs index 8d8e55e6..f56cba5d 100644 --- a/src/Split/uap10.0/ProcessPolyfill.cs +++ b/src/Split/uap10.0/ProcessPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,14 @@ public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeou [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static ProcessExitStatus Run(string fileName, IList? arguments = null, TimeSpan? timeout = default) => - Process.Run(BuildStartInfo(fileName, arguments), timeout); + public static ProcessExitStatus Run(string fileName, IList? arguments = null, bool silent = false, TimeSpan? timeout = default) + { + if (silent) + { + return Process.RunAndCaptureText(fileName, arguments, timeout).ExitStatus; + } + return Process.Run(BuildStartInfo(fileName, arguments), timeout); + } /// /// Asynchronously starts the process described by , waits for it to exit, and returns the exit status. /// @@ -65,8 +72,14 @@ public static async Task RunAsync(ProcessStartInfo startInfo, [SupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] - public static Task RunAsync(string fileName, IList? arguments = null, CancellationToken cancellationToken = default) => - Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + public static Task RunAsync(string fileName, IList? arguments = null, bool silent = false, CancellationToken cancellationToken = default) + { + if (silent) + { + return RunSilentAsync(fileName, arguments, cancellationToken); + } + return Process.RunAsync(BuildStartInfo(fileName, arguments), cancellationToken); + } /// /// Starts the process described by , captures its standard output and standard error as text, waits for it to exit, and returns the captured output. /// @@ -159,6 +172,34 @@ public static int StartAndForget(ProcessStartInfo startInfo) [UnsupportedOSPlatform("tvos")] public static int StartAndForget(string fileName, IList? arguments = null) => Process.StartAndForget(BuildStartInfo(fileName, arguments)); + /// + /// Gets the associated with the specified process identifier, and returns a value that indicates whether the operation succeeded. + /// + [SupportedOSPlatform("maccatalyst")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static bool TryGetProcessById(int processId, [NotNullWhen(true)] out Process? process) + { + if (processId <= 0) + { + throw new ArgumentOutOfRangeException(nameof(processId), processId, "Process identifier must be positive."); + } + try + { + process = Process.GetProcessById(processId); + return true; + } + catch (ArgumentException) + { + process = null; + return false; + } + } + } + static async Task RunSilentAsync(string fileName, IList? arguments, CancellationToken cancellationToken) + { + var output = await Process.RunAndCaptureTextAsync(fileName, arguments, cancellationToken); + return output.ExitStatus; } static Process StartOrThrow(ProcessStartInfo startInfo) { diff --git a/src/Tests/PolyfillTests_Process.cs b/src/Tests/PolyfillTests_Process.cs index 88abda28..88d2ce8e 100644 --- a/src/Tests/PolyfillTests_Process.cs +++ b/src/Tests/PolyfillTests_Process.cs @@ -168,6 +168,14 @@ public async Task Process_Run() await Assert.That(status.ExitCode).IsEqualTo(0); } + [Test] + public async Task Process_Run_Silent() + { + var status = Process.Run("dotnet", new[] { "--info" }, silent: true); + await Assert.That(status.Canceled).IsFalse(); + await Assert.That(status.ExitCode).IsEqualTo(0); + } + [Test] public async Task Process_RunAsync() { @@ -177,12 +185,45 @@ public async Task Process_RunAsync() await Assert.That(status.ExitCode).IsEqualTo(0); } + [Test] + public async Task Process_RunAsync_Silent() + { + var status = await Process.RunAsync("dotnet", new[] { "--info" }, silent: true); + await Assert.That(status.Canceled).IsFalse(); + await Assert.That(status.ExitCode).IsEqualTo(0); + } + + [Test] + public async Task Process_TryGetProcessById_Found() + { + var currentId = Process.GetCurrentProcess().Id; + var found = Process.TryGetProcessById(currentId, out var process); + await Assert.That(found).IsTrue(); + await Assert.That(process).IsNotNull(); + await Assert.That(process!.Id).IsEqualTo(currentId); + process.Dispose(); + } + + [Test] + public async Task Process_TryGetProcessById_NotFound() + { + var found = Process.TryGetProcessById(int.MaxValue, out var process); + await Assert.That(found).IsFalse(); + await Assert.That(process).IsNull(); + } + + [Test] + public async Task Process_TryGetProcessById_InvalidId() + { + await Assert.That(() => { Process.TryGetProcessById(0, out _); }).Throws(); + } + [Test] public async Task Process_RunAsync_Canceled() { using var source = new CancellationTokenSource(); source.Cancel(); - var status = await Process.RunAsync("dotnet", new[] { "--info" }, source.Token); + var status = await Process.RunAsync("dotnet", new[] { "--info" }, cancellationToken: source.Token); await Assert.That(status.Canceled).IsTrue(); } From f47fd76a41537a603b6011384a5200ef9776baf3 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 15 Jul 2026 07:21:47 +1000 Subject: [PATCH 2/2] Update readme.md --- readme.md | 81 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/readme.md b/readme.md index 199543e9..fe9c395b 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ The package targets `netstandard2.0` and is designed to support the following ru * `uap10` -**API count: 1021** +**API count: 1022** ### Per Target Framework @@ -97,25 +97,25 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| | netstandard2.0 | 8.0KB | 353.0KB | +345.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netstandard2.1 | 8.5KB | 306.5KB | +298.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 351.5KB | +343.0KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| net462 | 7.0KB | 355.0KB | +348.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netstandard2.1 | 8.5KB | 306.5KB | +298.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net461 | 8.5KB | 351.5KB | +343.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| net462 | 7.0KB | 355.5KB | +348.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | | net47 | 7.0KB | 355.0KB | +348.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 354.0KB | +345.5KB | +8.0KB | +6.5KB | +9.0KB | +13.5KB | -| net472 | 8.5KB | 352.5KB | +344.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net48 | 8.5KB | 352.5KB | +344.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| net481 | 8.5KB | 352.5KB | +344.0KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | -| netcoreapp2.0 | 9.0KB | 330.5KB | +321.5KB | +8.5KB | +6.0KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 302.5KB | +293.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| netcoreapp3.1 | 9.5KB | 301.0KB | +291.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net5.0 | 9.5KB | 265.0KB | +255.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 206.5KB | +196.5KB | +9.5KB | +7.0KB | +512bytes | +3.5KB | -| net7.0 | 10.0KB | 169.0KB | +159.0KB | +9.0KB | +5.5KB | +512bytes | +3.5KB | -| net8.0 | 9.5KB | 139.5KB | +130.0KB | +8.0KB | | +512bytes | +3.0KB | -| net9.0 | 9.5KB | 92.5KB | +83.0KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 70.0KB | +60.0KB | +9.0KB | | +1.0KB | +3.5KB | +| net471 | 8.5KB | 354.0KB | +345.5KB | +9.5KB | +6.5KB | +9.5KB | +14.0KB | +| net472 | 8.5KB | 353.0KB | +344.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net48 | 8.5KB | 353.0KB | +344.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net481 | 8.5KB | 353.0KB | +344.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.0 | 9.0KB | 330.5KB | +321.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp2.2 | 9.0KB | 310.0KB | +301.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 303.0KB | +293.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.1 | 9.5KB | 301.0KB | +291.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net5.0 | 9.5KB | 265.0KB | +255.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| net6.0 | 10.0KB | 206.5KB | +196.5KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | +| net7.0 | 10.0KB | 169.0KB | +159.0KB | +9.5KB | +5.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 139.5KB | +130.0KB | +8.5KB | +512bytes | +512bytes | +3.5KB | +| net9.0 | 10.0KB | 92.5KB | +82.5KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 70.0KB | +60.0KB | +9.0KB | | +512bytes | +3.5KB | | net11.0 | 10.0KB | 31.5KB | +21.5KB | +9.0KB | | +512bytes | +3.5KB | @@ -124,25 +124,25 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| | netstandard2.0 | 8.0KB | 516.0KB | +508.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netstandard2.1 | 8.5KB | 442.9KB | +434.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 515.6KB | +507.1KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| net462 | 7.0KB | 519.1KB | +512.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netstandard2.1 | 8.5KB | 442.9KB | +434.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net461 | 8.5KB | 515.6KB | +507.1KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| net462 | 7.0KB | 519.6KB | +512.6KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | | net47 | 7.0KB | 518.8KB | +511.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 517.5KB | +509.0KB | +15.7KB | +8.2KB | +13.9KB | +18.9KB | -| net472 | 8.5KB | 514.9KB | +506.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net48 | 8.5KB | 514.9KB | +506.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| net481 | 8.5KB | 514.9KB | +506.4KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | -| netcoreapp2.0 | 9.0KB | 482.9KB | +473.9KB | +16.2KB | +7.7KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 433.9KB | +424.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| netcoreapp3.1 | 9.5KB | 432.4KB | +422.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net5.0 | 9.5KB | 378.2KB | +368.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 299.6KB | +289.6KB | +17.2KB | +8.7KB | +1.1KB | +4.2KB | -| net7.0 | 10.0KB | 243.5KB | +233.5KB | +16.6KB | +6.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 198.5KB | +189.0KB | +15.5KB | +299bytes | +1.1KB | +3.7KB | -| net9.0 | 9.5KB | 130.4KB | +120.9KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 99.5KB | +89.5KB | +16.5KB | | +1.6KB | +4.2KB | +| net471 | 8.5KB | 517.5KB | +509.0KB | +17.2KB | +8.2KB | +14.4KB | +19.4KB | +| net472 | 8.5KB | 515.4KB | +506.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net48 | 8.5KB | 515.4KB | +506.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net481 | 8.5KB | 515.4KB | +506.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.0 | 9.0KB | 482.9KB | +473.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp2.2 | 9.0KB | 450.2KB | +441.2KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 434.4KB | +424.9KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.1 | 9.5KB | 432.4KB | +422.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net5.0 | 9.5KB | 378.2KB | +368.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| net6.0 | 10.0KB | 299.6KB | +289.6KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | +| net7.0 | 10.0KB | 243.5KB | +233.5KB | +17.1KB | +6.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 198.5KB | +189.0KB | +16.0KB | +811bytes | +1.1KB | +4.2KB | +| net9.0 | 10.0KB | 130.4KB | +120.4KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 99.5KB | +89.5KB | +16.5KB | | +1.1KB | +4.2KB | | net11.0 | 10.0KB | 46.9KB | +36.9KB | +16.5KB | | +1.1KB | +4.2KB | @@ -1320,15 +1320,18 @@ The class `Polyfill` includes the following extension methods: * `Task<(string StandardOutput, string StandardError)> ReadAllTextAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.readalltextasync?view=net-11.0) * `Task WaitForExitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexitasync?view=net-11.0) * `ProcessExitStatus Run(ProcessStartInfo, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-diagnostics-processstartinfo-system-nullable((system-timespan)))) - * `ProcessExitStatus Run(string, IList?, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-string-system-collections-generic-ilist((system-string))-system-nullable((system-timespan)))) + * `ProcessExitStatus Run(string, IList?, bool, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.run?view=net-11.0#system-diagnostics-process-run(system-string-system-collections-generic-ilist((system-string))-system-boolean-system-nullable((system-timespan)))) + * Note: When silent is true, standard output and error are suppressed by redirecting and discarding them (rather than binding to the null device as on net11); standard input remains connected. * `ProcessTextOutput RunAndCaptureText(ProcessStartInfo, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetext?view=net-11.0#system-diagnostics-process-runandcapturetext(system-diagnostics-processstartinfo-system-nullable((system-timespan)))) * `ProcessTextOutput RunAndCaptureText(string, IList?, TimeSpan?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetext?view=net-11.0#system-diagnostics-process-runandcapturetext(system-string-system-collections-generic-ilist((system-string))-system-nullable((system-timespan)))) * `Task RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetextasync?view=net-11.0#system-diagnostics-process-runandcapturetextasync(system-diagnostics-processstartinfo-system-threading-cancellationtoken)) * `Task RunAndCaptureTextAsync(string, IList?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runandcapturetextasync?view=net-11.0#system-diagnostics-process-runandcapturetextasync(system-string-system-collections-generic-ilist((system-string))-system-threading-cancellationtoken)) * `Task RunAsync(ProcessStartInfo, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-diagnostics-processstartinfo-system-threading-cancellationtoken)) - * `Task RunAsync(string, IList?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-string-system-collections-generic-ilist((system-string))-system-threading-cancellationtoken)) + * `Task RunAsync(string, IList?, bool, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.runasync?view=net-11.0#system-diagnostics-process-runasync(system-string-system-collections-generic-ilist((system-string))-system-boolean-system-threading-cancellationtoken)) + * Note: When silent is true, standard output and error are suppressed by redirecting and discarding them (rather than binding to the null device as on net11); standard input remains connected. * `int StartAndForget(ProcessStartInfo)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.startandforget?view=net-11.0#system-diagnostics-process-startandforget(system-diagnostics-processstartinfo)) * `int StartAndForget(string, IList?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.startandforget?view=net-11.0#system-diagnostics-process-startandforget(system-string-system-collections-generic-ilist((system-string)))) + * `bool TryGetProcessById(int, Process?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.trygetprocessbyid?view=net-11.0) #### PropertyInfo