Larcanum.ShellToolkit 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Larcanum.ShellToolkit --version 1.0.0                
NuGet\Install-Package Larcanum.ShellToolkit -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Larcanum.ShellToolkit" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Larcanum.ShellToolkit --version 1.0.0                
#r "nuget: Larcanum.ShellToolkit, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Larcanum.ShellToolkit as a Cake Addin
#addin nuget:?package=Larcanum.ShellToolkit&version=1.0.0

// Install Larcanum.ShellToolkit as a Cake Tool
#tool nuget:?package=Larcanum.ShellToolkit&version=1.0.0                

GitHub

Overview

The goal of this library is to provide a set of tools to start and interact with processes on the host system in a way that is similarly easy to use as Bash or oder shells. First and foremost this means providing a convenient API on top of the rather crusty and awkward System.Diagnostics.Process and System.Diagnostics.ProcessStartInfo. On top of that, the library provides methods for building pipelines of commands similar to how pipes work in Bash.

One common use case and the reason for creating this library is the creation of custom .NET command line tools that rely on other programs like git, 7z, dotnet, jq, sed, awk, etc. to avoid reinventing the wheel.

Examples

The examples here are assuming that the following command line tools are available in your system PATH

Capturing and Processing simple Command Output

var runner = CommandRunner.Create();

var version = Version.Parse((await runner.CaptureAsync(Command.Create("dotnet", ["--version"]))).Output!);
// version.Major = 8
// version.Minor = 0
// version.Build = 200

Running Command Output through Filters and into a File

var runner = CommandRunner.Create();
var tempFile = new FileInfo(Path.GetTempFileName());

var pipeline = Command.Create("dotnet", ["list", @"C:\path\to\ShellToolkit.csproj", "package", "--format", "json"])
    .Pipe(Command.Create("jq", [".projects.[].frameworks.[].topLevelPackages.[].id"]))
    .Pipe(tempFile);

if (await runner.ExecAsync(pipeline) != 0)
{
    throw new Exception("Pipeline failed");
}

var result = await File.ReadAllTextAsync(tempFile.FullName);
// result = "Microsoft.Extensions.Logging.Abstractions"
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 439 8/29/2024
1.0.1 112 8/29/2024
1.0.0 108 8/29/2024