Skip to content
C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#.
Branch: master
Clone or download
Latest commit c34e15c May 24, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Fixes #5 - Environment variable support Dec 6, 2013
.gitattributes Initial project structure Nov 12, 2012
.gitignore Adding nuspec and updating versions Nov 13, 2012
LICENSE Add LICENSE file May 24, 2016 Clarification in README about env variables Dec 8, 2013
build.yml Updating artifactsDir convention to build folder Feb 13, 2014
install.ps1 Adding ydeliver build scripts Sep 12, 2013
install.yml Adding ydeliver build scripts Sep 12, 2013


A C# Library to run external programs / commands in a simpler way. It is inspired from the sh library for Python, and is intended to showcase the "dynamic" features of C#

How to get it?

Cmd is available through the Nuget Package Manager.

Or, you can build it from source.

How to use it?

Create a dynamic instance of Cmd:

dynamic cmd = new Cmd();

Now, you can call commands off cmd:


The above would be equivalent to git clone

You can pass flags by naming the arguments:

cmd.git.log(grep: "test");

The above would be equivalent to git log --grep test


cmd.git.branch(a: true);

which would be equivalent to git branch -a

Note that single character flags are mapped as -<flag> and multi-character ones are mapped as --<flag>

Also, non-string values are ignored and if there is no flag, the argument is not considered.

You can call multiple commands off the same instance of cmd:

var gitOutput = cmd.git();
var svnOutput = cmd.svn();

Note that the commands can be case sensitive, and as such cmd.git is not same as, say, cmd.Git.

How to set environment variables?

Environment variables can be set for the process by calling ._Env method on an instance of Cmd and pass the set of environment variables with their values as a Dictionary<string, string>:

cmd._Env(new Dictionary<string, string> { { "GIT_DIR", @"C:\" } });

Note that this replaces existing variables with the new values.


You can use cmd to run command on, well, cmd and Powershell. Choose the shell you want to use while creating cmd:

dynamic cmd = new Cmd(Shell.Cmd);
dynamic posh = new Cmd(Shell.Powershell);

cmd.dir() is equivalent to cmd /c dir

When using Shell.Cmd, flags are constructed using / instead of - and --

Powershell support is still a work in progress.

What's ahead?

cmd is in a very nascent stage. More sh like goodness coming soon.

You can’t perform that action at this time.