All Projects → adamralph → Simple Exec

adamralph / Simple Exec

Licence: apache-2.0
🏃 A .NET library that runs external commands.

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.

The command is echoed to standard error (stderr) for visibility.

Platform support: .NET Standard 1.3 and upwards.

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

var output1 = Read("foo.exe");
var output2 = Read("foo.exe", "arg1 arg2", "my-working-directory");

var output3 = await ReadAsync("foo.exe");
var output4 = await ReadAsync("foo.exe", "arg1 arg2", "my-working-directory");

Other optional arguments

bool noEcho = false,
string echoPrefix = null,
Action<IDictionary<string, string>> configureEnvironment = null,
bool createNoWindow = false,
CancellationToken cancellationToken = default,

Exceptions

If the command has a non-zero exit code, a NonZeroExitCodeException is thrown with an int ExitCode property and a message in the form of:

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

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

Run by Gregor Cresnar from the Noun Project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].