Giter Site home page Giter Site logo

medallionshell's Introduction

MedallionShell

MedallionShell is a lightweight library that vastly simplifies working with processes in .NET apps.

Download the NuGet package NuGet Status

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");

Release Notes

  • 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 Fixed bug with standard error (thanks nsdfxela!)
  • 1.0.2 Fixed bug where timeout would suppress errors from ThrowOnError option
  • 1.0.1 Allowed for argument ommission in Command.Run(), other minor fixes
  • 1.0.0 Initial release

Building The Code

You will need:

  • VisualStudio 2015 or higher (community edition is fine) download
  • .NET Core Tooling for VisualStudio download
  • .NET Core SDK for Windows download

MedallionShell can be built from VisualStudio or from the command line using Cake:

powershell ./build.ps1

Running the cake build script will build the solution and execute the tests against both .NET Core and the .NET Framework (this is key, since the XUnit runner in VS does not allow you to pick which build to use when running unit tests). Cake will also create the NuGet package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.