Kehlet.Scripting 1.1.0

dotnet add package Kehlet.Scripting --version 1.1.0
                    
NuGet\Install-Package Kehlet.Scripting -Version 1.1.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="Kehlet.Scripting" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kehlet.Scripting" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Kehlet.Scripting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kehlet.Scripting --version 1.1.0
                    
#r "nuget: Kehlet.Scripting, 1.1.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.
#:package Kehlet.Scripting@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kehlet.Scripting&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Kehlet.Scripting&version=1.1.0
                    
Install as a Cake Tool

Kehlet.Scripting

Tiny shell helpers for C# scripts and small utilities.

  • No dependencies
  • Single file, copy-paste friendly
  • Works with dotnet run app.cs
  • Also available as a package

Install

Option 1: Use as a package

#:package Kehlet.Scripting

Option 2: Copy-paste

Copy Shell.cs into your project.


Quick start

using Kehlet.Scripting;

var result = await "echo hello".RunAsync();

Console.WriteLine(result.StandardOutput);

Async / sync

// Async (recommended)
var result = await "echo hello".RunAsync();

// Sync
var result = "echo hello".Run();

Shell selection

await "ls -la".RunAsync(ShellKind.Bash);
await "git status".RunAsync(ShellKind.Sh);
await "dir".RunAsync(ShellKind.Cmd);
await "echo $env:USERPROFILE".RunAsync(ShellKind.Pwsh);
await "ls -la".RunAsync(ShellKind.WslBash);

Platform defaults

Run() / RunAsync() without specifying a shell uses:

  • Windowspwsh
  • Linux / macOS/bin/sh
await "echo hi".RunAsync();

Pattern matching

if (await "git diff --quiet".RunAsync() is { ExitCode: 0 })
{
    Console.WriteLine("No changes");
}

Deconstruction

var (stdout, stderr, code) = await "echo hello".RunAsync();

Cancellation

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));

await "sleep 10".RunAsync(cts.Token);

Cancelling will attempt to terminate the process and its entire process tree.


Operator shorthand

var result = await !"echo hello";

Equivalent to:

await "echo hello".RunAsync();

Result type

public readonly record struct ProcessResult(
    string StandardOutput,
    string StandardError,
    int ExitCode
);

Shells

public enum ShellKind
{
    Sh,
    Bash,
    Cmd,
    Pwsh,
    WslBash,
    PlatformDefault,
}

Notes

  • Commands are passed directly to the shell (no escaping or validation).
  • Command syntax must match the selected shell.
  • Output is fully buffered and returned after the process exits (not streamed).
  • Shell executables must exist on the system (pwsh, /bin/sh, bash, etc.).

License

MIT

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net11.0

    • No dependencies.

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.1.0 107 4/15/2026
1.0.0 102 4/15/2026