{"id":13458284,"url":"https://github.com/adamralph/simple-exec","last_synced_at":"2025-05-14T01:07:43.950Z","repository":{"id":26645188,"uuid":"109606180","full_name":"adamralph/simple-exec","owner":"adamralph","description":"🏃 A .NET library that runs external commands.","archived":false,"fork":false,"pushed_at":"2025-03-20T00:55:50.000Z","size":932,"stargazers_count":730,"open_issues_count":4,"forks_count":50,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-04-04T15:04:37.432Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamralph.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"adamralph"}},"created_at":"2017-11-05T18:46:20.000Z","updated_at":"2025-03-27T10:56:59.000Z","dependencies_parsed_at":"2023-02-16T06:31:35.589Z","dependency_job_id":"69543d78-c241-4e96-bf2f-b075d4c15eeb","html_url":"https://github.com/adamralph/simple-exec","commit_stats":{"total_commits":537,"total_committers":7,"mean_commits":76.71428571428571,"dds":"0.25325884543761634","last_synced_commit":"a18aaf5548892c8bf6c6f0e0d8249a31eb785217"},"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamralph%2Fsimple-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamralph%2Fsimple-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamralph%2Fsimple-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamralph%2Fsimple-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamralph","download_url":"https://codeload.github.com/adamralph/simple-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248475726,"owners_count":21110138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T09:00:49.638Z","updated_at":"2025-04-11T20:29:16.766Z","avatar_url":"https://github.com/adamralph.png","language":"C#","readme":"# SimpleExec\r\n\r\n![SimpleExec](https://raw.githubusercontent.com/adamralph/simple-exec/092a28b5dcd011725cef7f3b207fcb9a056b651d/assets/simple-exec.svg)\r\n\r\n_[![NuGet version](https://img.shields.io/nuget/v/SimpleExec.svg?style=flat)](https://www.nuget.org/packages/SimpleExec)_\r\n\r\n_[![CI](https://github.com/adamralph/simple-exec/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/adamralph/simple-exec/actions/workflows/ci.yml?query=branch%3Amain)_\r\n_[![CodeQL analysis](https://github.com/adamralph/simple-exec/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/adamralph/simple-exec/actions/workflows/codeql-analysis.yml?query=branch%3Amain)_\r\n_[![InferSharp](https://github.com/adamralph/simple-exec/actions/workflows/infer-sharp.yml/badge.svg?branch=main)](https://github.com/adamralph/simple-exec/actions/workflows/infer-sharp.yml?query=branch%3Amain)_\r\n_[![Lint](https://github.com/adamralph/simple-exec/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/adamralph/simple-exec/actions/workflows/lint.yml?query=branch%3Amain)_\r\n_[![Spell check](https://github.com/adamralph/simple-exec/actions/workflows/spell-check.yml/badge.svg?branch=main)](https://github.com/adamralph/simple-exec/actions/workflows/spell-check.yml?query=branch%3Amain)_\r\n\r\nSimpleExec is a [.NET library](https://www.nuget.org/packages/SimpleExec) that runs external commands. It wraps [`System.Diagnostics.Process`](https://apisof.net/catalog/System.Diagnostics.Process) to make things easier.\r\n\r\nSimpleExec intentionally does not invoke the system shell.\r\n\r\nPlatform support: [.NET 8.0 and later](https://dot.net).\r\n\r\n- [Quick start](#quick-start)\r\n- [Run](#run)\r\n- [Read](#read)\r\n- [Other optional arguments](#other-optional-arguments)\r\n- [Exceptions](#exceptions)\r\n\r\n## Quick start\r\n\r\n```c#\r\nusing static SimpleExec.Command;\r\n```\r\n\r\n```c#\r\nRun(\"foo\", \"arg1 arg2\");\r\n```\r\n\r\n## Run\r\n\r\n```c#\r\nRun(\"foo\");\r\nRun(\"foo\", \"arg1 arg2\");\r\nRun(\"foo\", new[] { \"arg1\", \"arg2\" });\r\n\r\nawait RunAsync(\"foo\");\r\nawait RunAsync(\"foo\", \"arg1 arg2\");\r\nawait RunAsync(\"foo\", new[] { \"arg1\", \"arg2\" });\r\n```\r\n\r\nBy default, the command is echoed to standard output (stdout) for visibility.\r\n\r\n## Read\r\n\r\n```c#\r\nvar (standardOutput1, standardError1) = await ReadAsync(\"foo\");\r\nvar (standardOutput2, standardError2) = await ReadAsync(\"foo\", \"arg1 arg2\");\r\nvar (standardOutput3, standardError3) = await ReadAsync(\"foo\", new[] { \"arg1\", \"arg2\" });\r\n```\r\n\r\n## Other optional arguments\r\n\r\n```c#\r\nstring workingDirectory = \"\",\r\nbool noEcho = false,\r\nstring? echoPrefix = null,\r\nAction\u003cIDictionary\u003cstring, string?\u003e\u003e? configureEnvironment = null,\r\nbool createNoWindow = false,\r\nEncoding? encoding = null,\r\nFunc\u003cint, bool\u003e? handleExitCode = null,\r\nstring? standardInput = null,\r\nbool cancellationIgnoresProcessTree = false,\r\nCancellationToken cancellationToken = default,\r\n```\r\n\r\n## Exceptions\r\n\r\nIf the command has a non-zero exit code, an `ExitCodeException` is thrown with an `int` `ExitCode` property and a message in the form of:\r\n\r\n```c#\r\n$\"The process exited with code {ExitCode}.\"\r\n```\r\n\r\nIn the case of `ReadAsync`, an `ExitCodeReadException` 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:\r\n\r\n```c#\r\n$@\"The process exited with code {ExitCode}.\r\n\r\nStandard Output:\r\n\r\n{Out}\r\n\r\nStandard Error:\r\n\r\n{Error}\"\r\n```\r\n\r\n### Overriding default exit code handling\r\n\r\nMost 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](https://ss64.com/nt/robocopy.html) returns an exit code less than 8 when it succeeds and 8 or greater when a failure occurs.\r\n\r\nThe 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.\r\n\r\nFor example, when running Robocopy, exception throwing should be suppressed for an exit code less than 8:\r\n\r\n```c#\r\nRun(\"ROBOCOPY\", \"from to\", handleExitCode: code =\u003e code \u003c 8);\r\n```\r\n\r\nNote that it may be useful to record the exit code. For example:\r\n\r\n```c#\r\nvar exitCode = 0;\r\nRun(\"ROBOCOPY\", \"from to\", handleExitCode: code =\u003e (exitCode = code) \u003c 8);\r\n\r\n// see https://ss64.com/nt/robocopy-exit.html\r\nvar oneOrMoreFilesCopied = exitCode \u0026 1;\r\nvar extraFilesOrDirectoriesDetected = exitCode \u0026 2;\r\nvar misMatchedFilesOrDirectoriesDetected = exitCode \u0026 4;\r\n```\r\n\r\n---\r\n\r\n\u003csub\u003e[Run](https://thenounproject.com/term/target/975371) by [Gregor Cresnar](https://thenounproject.com/grega.cresnar/) from [the Noun Project](https://thenounproject.com/).\u003c/sub\u003e\r\n","funding_links":["https://github.com/sponsors/adamralph"],"categories":["C\\#","C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamralph%2Fsimple-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamralph%2Fsimple-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamralph%2Fsimple-exec/lists"}