SimpleExec 9.0.0-alpha.1

This is a prerelease version of SimpleExec.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SimpleExec --version 9.0.0-alpha.1
NuGet\Install-Package SimpleExec -Version 9.0.0-alpha.1
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="SimpleExec" Version="9.0.0-alpha.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleExec --version 9.0.0-alpha.1
#r "nuget: SimpleExec, 9.0.0-alpha.1"
#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 SimpleExec as a Cake Addin
#addin nuget:?package=SimpleExec&version=9.0.0-alpha.1&prerelease

// Install SimpleExec as a Cake Tool
#tool nuget:?package=SimpleExec&version=9.0.0-alpha.1&prerelease

SimpleExec

SimpleExec

NuGet version

Build status CodeQL analysis Lint Spell check

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.

By default, the command is echoed to standard error (stderr) for visibility.

Platform support: .NET Standard 2.0 and later.

Quick start

using static SimpleExec.Command;
Run("foo.exe", "arg1 arg2");

API

Run

Run("foo.exe");
Run("foo.exe", "arg1 arg2", "my-working-directory");

await RunAsync("foo.exe");
await RunAsync("foo.exe", "arg1 arg2", "my-working-directory");

Read

// ReadAsync returns a CommandReadResult object with Out and Error properties representing standard out (stdout) and standard error (stderr)
var result1 = await ReadAsync("foo.exe");
var result2 = await ReadAsync("foo.exe", "arg1 arg2", "my-working-directory");

Other optional arguments

bool noEcho = false,
string windowsName = null,
string windowsArgs = null,
string echoPrefix = null,
Action<IDictionary<string, string>> configureEnvironment = null,
bool createNoWindow = false,
Func<int, bool> handleExitCode = null,
CancellationToken cancellationToken = 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 process exited with code {ExitCode}."

In the case of ReadAsync, a ReadException is thrown, which inherits from ExitCodeException, and has string Out and Error properties, representing standard out (stdout) and standard error (stderr), and a message in the form of:

$@"The process exited with code {ExitCode}.

Standard Output:

{Out}

Standard Error:

{Error}"
Overriding default exit code handling

The throwing of exceptions for specific non-zero exit codes can 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:

Run("ROBOCOPY", "from to", handleExitCode: code => code < 8);

Note that it may be useful to record the exit code. For example:

var exitCode = 0;
var result = 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;

Windows

🙄

Sometimes, for whatever wonderful reasons, it's necessary to run a different command on Windows. For example, when running Yarn, some combination of mysterious factors may require that you explicitly run cmd.exe with Yarn as an argument, rather than running Yarn directly. The optional windowsNames and windowsArgs parameters may be used to specify a different command name and arguments for Windows:

Run("yarn", windowsName: "cmd", windowsArgs: "/c yarn");

<sub>Run by Gregor Cresnar from the Noun Project.</sub>

Product 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework 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 tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on SimpleExec:

Package Downloads
Vertiq.Testing.XUnit

A highly modular Framework to write Blazor Applications with a husstle free vertical sliced architecture - Easy. Flexible. Focused.

Xenial.Beer

Beer - Delicious dotnet build tools

Quick.Build

A lot of utils for build.

ILVerifier

A simple helper library to access provider-specific types when working with IDbConnection and friends.

LanceC.Tooling.DevOps

Provides DevOps tooling infrastructure.

GitHub repositories (42)

Showing the top 5 popular GitHub repositories that depend on SimpleExec:

Repository Stars
IdentityServer/IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
xunit/xunit
xUnit.net is a free, open source, community-focused unit testing tool for .NET.
JasperFx/marten
.NET Transactional Document DB and Event Store on PostgreSQL
aaubry/YamlDotNet
YamlDotNet is a .NET library for YAML
AppMetrics/AppMetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Version Downloads Last updated
12.0.0 51,810 1/15/2024
12.0.0-rc.1 384 12/25/2023
12.0.0-beta.1 222 12/24/2023
12.0.0-alpha.1 1,931 6/9/2023
11.0.0 371,394 8/21/2022
11.0.0-rc.1 573 7/22/2022
10.0.0 137,257 3/26/2022
10.0.0-beta.2 18,488 3/20/2022
10.0.0-beta.1 228 3/19/2022
9.1.0 14,817 3/19/2022
9.1.0-rc.1 202 3/13/2022
9.1.0-alpha.1 212 3/12/2022
9.0.0 4,249 3/12/2022
9.0.0-rc.4 1,201 2/26/2022
9.0.0-rc.3 8,094 12/30/2021
9.0.0-rc.2 257 12/23/2021
9.0.0-rc.1 162 12/23/2021
9.0.0-alpha.1 16,099 8/22/2021
8.0.0 471,536 7/5/2021
8.0.0-rc.1 449 6/26/2021
8.0.0-alpha.8 203 6/20/2021
8.0.0-alpha.7 170 6/19/2021
8.0.0-alpha.6 198 6/19/2021
8.0.0-alpha.5 197 6/19/2021
8.0.0-alpha.4 226 6/19/2021
8.0.0-alpha.3 921 6/13/2021
8.0.0-alpha.2 394 6/12/2021
8.0.0-alpha.1 235 6/12/2021
7.0.0 73,340 3/14/2021
7.0.0-alpha.2 298 3/13/2021
7.0.0-alpha.1 4,326 12/20/2020
6.4.0 67,430 12/20/2020
6.4.0-rc.1 1,542 12/5/2020
6.3.0 38,858 10/26/2020
6.2.0 242,502 12/21/2019
6.2.0-rc.1 1,324 12/15/2019
6.1.0 63,748 10/13/2019
6.1.0-rc.1 1,596 9/8/2019
6.1.0-beta.1 845 8/27/2019
6.0.0 52,254 7/13/2019
6.0.0-rc.1 406 6/27/2019
6.0.0-beta.1 647 6/12/2019
6.0.0-alpha.1 445 6/1/2019
5.0.1 19,397 2/10/2019
5.0.1-rc.1 594 2/10/2019
5.0.0 352 2/9/2019
5.0.0-beta.1 944 2/5/2019
5.0.0-alpha.2 338 2/4/2019
5.0.0-alpha.1 630 1/3/2019
4.2.0 17,928 12/8/2018
4.1.0 2,322 12/2/2018
4.0.0 372 11/27/2018
4.0.0-rc.1 409 11/26/2018
4.0.0-beta.1 700 11/20/2018
3.0.0 23,020 9/20/2018
2.3.0 2,333 8/25/2018
2.3.0-beta.1 446 8/11/2018
2.2.0 1,675 6/26/2018
2.1.0 1,489 5/20/2018
2.0.0 1,521 11/12/2017
1.0.0 2,511 11/5/2017