MedallionShell 1.5.1
See the version list below for details.
dotnet add package MedallionShell --version 1.5.1
NuGet\Install-Package MedallionShell -Version 1.5.1
<PackageReference Include="MedallionShell" Version="1.5.1" />
paket add MedallionShell --version 1.5.1
#r "nuget: MedallionShell, 1.5.1"
// Install MedallionShell as a Cake Addin #addin nuget:?package=MedallionShell&version=1.5.1 // Install MedallionShell as a Cake Tool #tool nuget:?package=MedallionShell&version=1.5.1
MedallionShell
MedallionShell is a lightweight library that vastly simplifies working with processes in .NET apps.
Built on top of the powerful, yet clunky System.Diagnostics.Process API, the MedallionShell API streamlines common use-cases, removes pitfalls, and integrates Process handling with .NET async/await and Tasks.
// processes are created and interacted with using the Command class
var cmd = Command.Run("path_to_grep", "some REGEX");
cmd.StandardInput.PipeFromAsync(new FileInfo("some path"));
// by default, all output streams are buffered, so there's no need to worry
// about deadlock
var outputLines = cmd.StandardOutput.GetLines().ToList();
var errorText = cmd.StandardError.ReadToEnd();
// by default, the underlying Process is automatically disposed
// so no using block is required
// and complex arguments are automatically escaped
var cmd = Command.Run("path_to_grep", "\\ some \"crazy\" REGEX \\");
// we can also do this inline using bash-style operator overloads
var lines = new List<string>();
var cmd = Command.Run("path_to_grep", "some REGEX") < new FileInfo("some path") > lines;
cmd.Wait();
// and we can even chain commands together with the pipe operator
var pipeline = Command.Run("path_to_grep", "some REGEX") | Command.Run("path_to_grep", "another REGEX");
// if you don't like using operators, you can use the equivalent fluent methods instead
var cmd = Command.Run("path_to_grep", some REGEX").RedirectFrom(new FileInfo("some path")).RedirectTo(lines);
// we can check a command's exit status using it's result
if (cmd.Result.Success) { ... }
// and perform async operations via its associated task
await cmd.Task;
// commands are also highly configurable
var cmd = Command.Run(
"path_to_grep",
new[] { "some REGEX" },
options: o => o
// arbitrarily configure the ProcessStartInfo
.StartInfo(si => si.RedirectStandardError = false)
// option to turn a non-zero exit code into an exception
.ThrowOnError()
// option to kill the command and throw TimeoutException if it doesn't finish
.Timeout(TimeSpan.FromMinutes(1))
...
);
// and if we want to keep using a common set of configuration options, we
// can package them up in a Shell object
var shell = new Shell(o => o.ThrowOnError()...);
shell.Run("path_to_grep", "some REGEX");
Cross-Platform Support
MedallionShell makes it easier to write process-handling code that works across different .NET platforms.
In particular, Mono has peculiarities in how it handles writing to an exited process that makes it very difficult to write correct cross-platform code. MedallionShell contains workarounds for these oddities that help ensure that code that works on .NET Framework/.NET Core runs seamlessly on Mono (see #6 and #22).
Release Notes
- 1.5.1 Improves Mono.Android compatibility (#22). Thanks sushihangover for reporting and testing the fix!
- 1.5.0
- 1.4.0
- Adds cancellation support (#18)
- Adds API for getting the underlying process ID for a command even with the DisposeOnExit option (#16)
- Adds API for consuming standard out and standard error lines together as a single stream (#14)
- Improves Mono compatibility (#6)
- Changes
Command.Result
andCommand.Wait()
to throw unwrapped exceptions instead ofAggregateException
- 1.3.0 Fixes default standard IO stream encodings (thanks xjfnet!) and added support for specifying a custom encoding
- 1.2.1 Adds .NET Core support (thanks kal!), adds new fluent APIs for each of the piping/redirection operators, and now respects StandardInput.AutoFlush when piping between commands
- 1.1.0 Adds AutoFlush support to StandardInput, and fixed bug where small amounts of flushed data became "stuck" in the StandardOutput buffer
- 1.0.3 Fixes bug with standard error (thanks <a href="https://github.com/nsdfxela">nsdfxela</a>!)
- 1.0.2 Fixes bug where timeout would suppress errors from ThrowOnError option
- 1.0.1 Allows for argument ommission in Command.Run(), other minor fixes
- 1.0.0 Initial release
Building The Code
You will need VisualStudio 2017 or higher (community edition is fine) download.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.0)
- System.Diagnostics.Process (>= 4.1.0)
NuGet packages (18)
Showing the top 5 NuGet packages that depend on MedallionShell:
Package | Downloads |
---|---|
NExifTool
.Net wrapper for the excellent ExifTool |
|
Testura.Android
Testura.Android is a lightweight test automation framework for Android built in C#. It contains tools and help classes to test, validate and interact with your Android device or emulator. |
|
MediaToolkit.NetCore
MediaToolkit port to .Net Core |
|
Microsoft.CST.AttackSurfaceAnalyzer
Microsoft Attack Surface Analyzer is an open source security tool that analyzes the attack surface of a target system and reports on potential security vulnerabilities introduced during the installation of software or system misconfiguration. This package contains the AttackSurfaceAnalyzer library. For the CLI Dotnet Tool, see Microsoft.CST.AttackSurfaceAnalyzer.CLI. |
|
CoenM.AsyncExifTool
AsynExifTool is a wrapper around the ExifTool lirbary making use of the '-stay-open' argument. |
GitHub repositories (8)
Showing the top 5 popular GitHub repositories that depend on MedallionShell:
Repository | Stars |
---|---|
Tyrrrz/CliWrap
Library for running command-line processes
|
|
rnwood/smtp4dev
smtp4dev - the fake smtp email server for development and testing
|
|
microsoft/AttackSurfaceAnalyzer
Attack Surface Analyzer can help you analyze your operating system's security configuration for changes during software installation.
|
|
webprofusion/certify
Professional ACME Client for Windows. Certificate Management UI, powered by Let's Encrypt and compatible with all ACME v2 CAs. Download from certifytheweb.com
|
|
ForNeVeR/Cesium
C compiler for the CLI platform
|
Version | Downloads | Last updated |
---|---|---|
1.6.2 | 484,309 | 11/15/2020 |
1.6.2-rc01 | 498 | 11/9/2020 |
1.6.1 | 376,158 | 12/23/2019 |
1.6.1-alpha01 | 424 | 12/17/2019 |
1.6.0 | 75,734 | 4/27/2019 |
1.5.1 | 135,960 | 4/30/2018 |
1.5.0 | 47,136 | 8/18/2017 |
1.4.0 | 1,411 | 7/1/2017 |
1.3.0 | 6,253 | 5/31/2017 |
1.2.1 | 9,167 | 10/12/2016 |
1.2.0 | 3,732 | 10/11/2016 |
1.1.0 | 20,531 | 7/12/2015 |
1.0.3 | 1,448 | 6/12/2015 |
1.0.2 | 2,052 | 2/22/2015 |
1.0.1 | 2,012 | 8/30/2014 |
1.0.0 | 1,766 | 8/23/2014 |