SimpleExec 13.0.0 (original) (raw)
SimpleExec is a .NET library that runs external commands. It wraps System.Diagnostics.Process to make things easier.
SimpleExec intentionally does not invoke the system shell.
Platform support: .NET 8.0 and later.
Quick start
using static SimpleExec.Command;
Run("foo", "arg1 arg2");
Run
Run("foo");
Run("foo", "arg1 arg2");
Run("foo", new[] { "arg1", "arg2" });
await RunAsync("foo");
await RunAsync("foo", "arg1 arg2");
await RunAsync("foo", new[] { "arg1", "arg2" });
By default, the command is echoed to standard output (stdout) for visibility.
Read
var (standardOutput1, standardError1) = await ReadAsync("foo");
var (standardOutput2, standardError2) = await ReadAsync("foo", "arg1 arg2");
var (standardOutput3, standardError3) = await ReadAsync("foo", new[] { "arg1", "arg2" });
Other optional arguments
Run/RunAsync
string workingDirectory = "",
Action<IDictionary<string, string?>>? configureEnvironment = null,
IEnumerable<string> secrets = null,
Func<int, bool>? handleExitCode = null,
string? echoPrefix = null,
bool noEcho = false,
bool cancellationIgnoresProcessTree = false,
bool createNoWindow = false,
CancellationToken ct = default,
ReadAsync
string workingDirectory = "",
Action<IDictionary<string, string?>>? configureEnvironment = null,
Func<int, bool>? handleExitCode = null,
Encoding? encoding = null,
string? standardInput = null,
bool cancellationIgnoresProcessTree = false,
CancellationToken ct = default,
Exceptions
If the command has a non-zero exit code, an ExitCodeException is thrown with an int ExitCode property and a message in the form of:
$"The command exited with code {ExitCode}."
In the case of ReadAsync, an ExitCodeReadException is thrown, which inherits from ExitCodeException, and has string StandardOutput and StandardError properties, representing standard output (stdout) and standard error (stderr), and a message in the form of:
$@"The command exited with code {ExitCode}.
Standard output:
{StandardOutput}
Standard error:
{StandardError}"
Overriding default exit code handling
Most programs return a zero exit code when they succeed and a non-zero exit code fail. However, there are some programs which return a non-zero exit code when they succeed. For example, Robocopy returns an exit code less than 8 when it succeeds and 8 or greater when a failure occurs.
The throwing of exceptions for specific non-zero exit codes may be suppressed by passing a delegate to handleExitCode which returns true when it has handled the exit code and default exit code handling should be suppressed, and returns false otherwise.
For example, when running Robocopy, exception throwing should be suppressed for an exit code less than 8:
Run("ROBOCOPY", "from to", handleExitCode: code => code < 8);
Note that it may be useful to record the exit code. For example:
var exitCode = 0;
Run("ROBOCOPY", "from to", handleExitCode: code => (exitCode = code) < 8);
// see https://ss64.com/nt/robocopy-exit.html
var oneOrMoreFilesCopied = exitCode & 1;
var extraFilesOrDirectoriesDetected = exitCode & 2;
var misMatchedFilesOrDirectoriesDetected = exitCode & 4;
Run by Gregor Cresnar from the Noun Project.
NuGet packages (14)
Showing the top 5 NuGet packages that depend on SimpleExec:
| Package | Downloads |
|---|---|
| Miracatch.Shared Shared code across Miracatch components. | 49.1K |
| EasyBuild.Tools Package Description | 44.7K |
| Vertiq.Testing.XUnit A highly modular framework for writing Blazor applications with a hassle-free, vertical-sliced architecture - Easy. Flexible. Focused. | 31.0K |
| Dex.IdentityServer4 OpenID Connect and OAuth 2.0 Framework for ASP.NET Core | 25.3K |
| Xenial.Beer Beer - Delicious dotnet build tools | 19.0K |
GitHub repositories (42)
Showing the top 20 popular GitHub repositories that depend on SimpleExec:
| Repository | Stars |
|---|---|
| xunit/xunit xUnit.net is a free, open source, community-focused unit testing tool for .NET. | 4.6K |
| aaubry/YamlDotNet YamlDotNet is a .NET library for YAML | 2.8K |
| adamhathcock/sharpcompress SharpCompress is a fully managed C# library to deal with many compression types and formats. | 2.6K |
| AppMetrics/AppMetrics App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application. | 2.2K |
| gothinkster/aspnetcore-realworld-example-app ASP.NET Core backend implementation for RealWorld | 2.1K |
| FakeItEasy/FakeItEasy The easy mocking library for .NET | 1.8K |
| ProxyKit/ProxyKit A toolkit to create code-first HTTP reverse proxies on ASP.NET Core | 1.1K |
| DuendeArchive/IdentityModel .NET standard helper library for claims-based identity, OAuth 2.0 and OpenID Connect. | 1.1K |
| adamralph/minver š· Minimalist .NET packages, developed by humans, for versioning software or content using Git tags. | 992 |
| SnapXL/SnapX SnapX is a free, open-source, cross-platform tool that lets you capture or record any area of your screen and instantly share it with a single keypress. Upload images, videos, text, and more to multiple supported destinationsāall with ease. ShareX fork | 945 |
| machine/machine.specifications Machine.Specifications is a Context/Specification framework for .NET that removes language noise and simplifies tests. | 900 |
| cofoundry-cms/cofoundry Cofoundry is an extensible and flexible .NET Core CMS & application framework focusing on code first development | 897 |
| DuendeArchive/IdentityModel.OidcClient Certified C#/NetStandard OpenID Connect Client Library for native mobile/desktop Applications (RFC 8252) | 614 |
| JasperFx/lamar Fast Inversion of Control Tool and Successor to StructureMap | 605 |
| Particular/Workshop SOA Done Right | 590 |
| spectresystems/snitch A tool that help you find duplicate transitive package references. | 493 |
| SQLStreamStore/SQLStreamStore Stream Store library targeting RDBMS based implementations for .NET | 467 |
| XamlAnimatedGif/XamlAnimatedGif A simple library to display animated GIF images in WPF apps (.NET Framework 4.5, .NET Core 3.1, .NET 5.0) | 465 |
| config-r/config-r Write your .NET configuration files in C# | 426 |
| JasperFx/jasper Next generation application development framework for .Net | 416 |