DotCon is a lightweight library that provides a simple and consistent interface for executing shell commands in various terminal environments. It follows the Factory Method design pattern to create terminal instances based on different shells (Bash, Cmd, PowerShell, Zsh).
You can add the DotCon library to your .NET project using the following methods:
dotnet add package DotCon --version 8.2.0
Or download/ clone the project and run the RunDocker.sh file, which will start up a conatiner with the classlib added to a console application.
To create a terminal instance, you can use one of the following methods:
Terminal.UseBashShell();
Terminal.UseCmdShell();
Terminal.UsePowershellShell();
Terminal.UseZshShell();
Or
Terminal.UseBashShell(options =>
{
// Configure terminal options
});
Run terminal commands or store script to be run at a later time with the Execute methods.
string output = terminal.Run("ls -la");
string output = await terminal.RunAsync("ls -la");
string output = terminal.ExecuteScript("myScript");
string output = await terminal.ExecuteScriptAsync("myScript");
Try to run commands in the terminal with a similer syntax to the TryParse
Terminal terminal = Terminal.UseBashShell();
string output;
bool success = terminal.TryRun("ls -la", out output);
if (success)
{
// Handle successful
}
else
{
// Handle execution error
Console.WriteLine($"Error: {output}");
}