CommandWrap
CommandWrap is an easy-to-use, open source library that encapsulates the syntax
from other command-line applications into usable .NET objects. It uses the power
of reflection in C# to allow you to define command-line syntax for virtually any
application. This provides a clean alternative to using messy Process.Start()
strings. The following example shows how to use the library with Windows's chkdsk
command:
CheckDiskCommand.cs
using namespace Crabwise.CommandWrap;
[CommandSyntaxAttribute("chkdsk")]
public class CheckDiskCommand : Command
{
[ParameterSyntaxAttribute("{arg}", Position = 1)]
public string Volume { get; set; }
[ParameterSyntaxAttribute("/F")]
public bool FixErrors { get; set; }
[ParameterSyntaxAttribute("/R")]
public bool CheckSectors { get; set; }
}
Using our new CheckDiskCommand class, we can run a new chkdsk
process from within our code:
Main.cs
public class Main
{
public static void Main(string[] args)
{
// The following command is equivalent to entering "chkdsk C: /F"
// on the command-line.
var command = new CheckDiskCommand
{
Volume = "C:",
FixErrors = true
};
command.Execute();
string output = command.StandardOutput;
string error = command.StandardError;
}
}
For a more detailed explanation, check out the examples page or if you're already convinced you can grab a copy of the DLL binary. CommandWrap is open source under the MIT license, so feel free to use it in your personal or commercial programs.