process/README.md

55 lines
No EOL
1.6 KiB
Markdown

# `Geekeey.Extensions.Process`
Process is a .NET library for interacting with external command-line interfaces. It provides a convenient model for
launching processes, redirecting input and output streams, awaiting completion, handling cancellation, and more.
## Features
- **Input and Output redirection:** flexible piping model, that allows to redirect the process's streams.
- **Immutability:** The `Command` object is immutable, ensuring thread safely and allowing sharing of a base
configuration.
## Getting Started
### Install the NuGet package:
```
dotnet add package Geekeey.Extensions.Process
```
You may need to add our NuGet Feed to your `nuget.config` this can be done by adding the following lines
```xml
<packageSources>
<add key="geekeey" value="https://git.geekeey.de/api/packages/geekeey/nuget/index.json" />
</packageSources>
```
### Configure
The package adds a global using for the functions in the `Prelude` class when the `ImplicitUsings` is enabled in
the `.csproj` file. This global using is recommended but can also be removed, by removing
the `Geekeey.Extensions.Process.Prelude` value from the item group `<Usings>`. For more information about that see
the `Project.props` file inside the project tree.
### Usage
```csharp
public static Task<int> Main()
{
var stdout = new StringBuilder();
var cmd = Run("git").WithArguments(["config", "--get", "user.name"]) | stdout;
await cmd.ExecuteAsync();
Console.WriteLine(stdout.ToString());
return 0;
}
```
```csharp
public static Task<int> Main()
{
var cmd = Run("cat").WithArguments(["file.txt"]) | Run("wc");
await cmd.ExecuteAsync();
Console.WriteLine(stdout.ToString());
}
```