External Process and Cli program running related abstractions implemented by CliInvoke
$ dotnet add package CliInvoke.CoreThis package contains Process Running and handling abstractions as well as common types used by implementing classes.
For an implementing package, check out CliInvoke.
Key Abstractions:
IProcessInvoker
IProcessConfigurationFactory
Piping:
IProcessPipeHandlerFluent Builders:
IArgumentsBuilder - An interface to help with Argument Building and argument escaping.IEnvironmentVariablesBuilder - An interface to help with setting Environment variables.IProcessConfigurationBuilder - An interface to fluently configure and build ProcessConfiguration objects.IProcessResourcePolicyBuilder - An interface to fluently configure and build ProcessResourcePolicy objects.IUserCredentialBuilder1 Specializations library distributed separately.
| Feature / Criterion | CliInvoke | CliWrap | ProcessX |
|---|---|---|---|
| Dedicated builder, model, and invoker types (clear separation of concerns) | ✅ | ❌ | ❌ |
| Dependency Injection registration extensions | ✅ | ❌ | ❌ |
| Installable via NuGet | ✅ | ✅ | ✅ |
| Official cross‑platform support (advertised: Windows/macOS/Linux/BSD) | ✅ | ✅* | ❌* |
| Buffered and non‑buffered execution modes | ✅ | ✅ | ✅ |
| Small surface area and minimal dependencies | ✅ | ✅ | ✅ |
| Licensing / repository additional terms | ✅ (MPL‑2.0) | ⚠️ (MIT; test project references a source‑available library; repo contains an informal "Terms of Use" statement) | ✅ (MIT) |
CliInvoke.Core packages can be installed via the .NET SDK CLI, Nuget via your IDE or code editor's package interface, or via the Nuget website.
| Package Name | Nuget Link | .NET SDK CLI command |
|---|---|---|
| CliInvoke.Core | CliInvoke.Core Nuget | dotnet add package CliInvoke.Core |
CliInvoke supports Windows, macOS, Linux, FreeBSD, Android, and potentially some other operating systems.
For more details see the list of supported platforms
ProcessConfiguration creation with Factory PatternThis approach uses the IProcessConfigurationFactory interface factory to create a ProcessConfiguration. It requires fewer parameters and sets up more defaults for you.
It can be provided with a Action<IProcessConfigurationBuilder> configure optional parameter where greater control is desired.
This example gets a non buffered ProcessResult that contains basic process exit code, id, and other information.
using CliInvoke.Core.Factories;
using CliInvoke.Core;
using Microsoft.Extensions.DependencyInjection;
// Dependency Injection setup code ommitted for clarity
// Get IProcessConfigurationFactory
IProcessConfigurationFactory processConfigFactory = serviceProvider.GetRequiredService<IProcessConfigurationFactory>();
// Get IProcessConfigurationInvoker
IProcessInvoker _invoker_ = serviceProvider.GetRequiredService<IProcessInvoker>();
// Simply create the process configuration.
ProcessConfiguration configuration = processConfigFactory.Create("path/to/exe", "arguments");
// Run the process configuration and get the results.
ProcessResult result = await _invoker.ExecuteAsync(configuration, CancellationToken.None);
This example gets a BufferedProcessResult which contains redirected StandardOutput and StandardError as strings.
using CliInvoke.Core.Factories;
using CliInvoke.Core;
using Microsoft.Extensions.DependencyInjection;
// Dependency Injection setup code ommitted for clarity
// Get IProcessConfigurationFactory
IProcessConfigurationFactory processConfigFactory = serviceProvider.GetRequiredService<IProcessConfigurationFactory>();
// Get IProcessConfigurationInvoker
IProcessnvoker _invoker_ = serviceProvider.GetRequiredService<IProcessInvoker>();
// Simply create the process configuration.
ProcessConfiguration configuration = processConfigFactory.Create("path/to/exe", "arguments");
// Run the process configuration and get the results.
BufferedProcessResult result = await _invoker.ExecuteBufferedAsync(configuration, CancellationToken.None);
The following examples shows how to configure and build a ProcessConfiguration depending on whether Buffering the output is desired.
This example gets a non buffered ProcessResult that contains basic process exit code, id, and other information.
using CliInvoke;
using CliInvoke.Core;
using CliInvoke.Builders;
using CliInvoke.Core.Builders;
using Microsoft.Extensions.DependencyInjection;
//Namespace and class code ommitted for clarity
// ServiceProvider and Dependency Injection setup code ommitted for clarity
IProcessInvoker _processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();
// Fluently configure your Command.
IProcessConfigurationBuilder builder = new ProcessConfigurationBuilder("Path/To/Executable")
.SetArguments(["arg1", "arg2"])
.SetWorkingDirectory("/Path/To/Directory");
// Build it as a ProcessConfiguration object when you're ready to use it.
ProcessConfiguration config = builder.Build();
// Execute the process through ProcessInvoker and get the results.
ProcessResult result = await _processConfigInvoker.ExecuteAsync(config);
This example gets a BufferedProcessResult which contains redirected StandardOutput and StandardError as strings.
using CliInvoke;
using CliInvoke.Builders;
using CliInvoke.Core;
using CliInvoke.Core.Builders;
using Microsoft.Extensions.DependencyInjection;
//Namespace and class code ommitted for clarity
// ServiceProvider and Dependency Injection setup code ommitted for clarity
IProcessInvoker _processInvoker = serviceProvider.GetRequiredService<IProcessInvoker>();
// Fluently configure your Command.
IProcessConfigurationBuilder builder = new ProcessConfigurationBuilder("Path/To/Executable")
.SetArguments(["arg1", "arg2"])
.SetWorkingDirectory("/Path/To/Directory")
.RedirectStandardOutput(true)
.RedirectStandardError(true);
// Build it as a ProcessConfiguration object when you're ready to use it.
ProcessConfiguration config = builder.Build();
// Execute the process through ProcessInvoker and get the results.
BufferedProcessResult result = await _processInvoker.ExecuteBufferedAsync(config);
This project would like to thank the following projects for their work:
For more information, please see the THIRD_PARTY_NOTICES file.