fwRelik.Terminal
0.2.0
See the version list below for details.
dotnet add package fwRelik.Terminal --version 0.2.0
NuGet\Install-Package fwRelik.Terminal -Version 0.2.0
<PackageReference Include="fwRelik.Terminal" Version="0.2.0" />
paket add fwRelik.Terminal --version 0.2.0
#r "nuget: fwRelik.Terminal, 0.2.0"
// Install fwRelik.Terminal as a Cake Addin
#addin nuget:?package=fwRelik.Terminal&version=0.2.0
// Install fwRelik.Terminal as a Cake Tool
#tool nuget:?package=fwRelik.Terminal&version=0.2.0
fwRelik.Terminal
Makes it easier to enter commands and process data from output.
Under the hood, the process uses a PowerShell.
TerminalClient Class
- Namespace:
fwRelik.Terminal
- Assembly:
fwRelik.Terminal.dll
📋 Methods
Methods | Description |
---|---|
Command | Allows you to execute a command and process. |
📄 Examples
Command
const string command = "dir | Select-Object -Property Name";
TerminalClient.Command(command, process =>
{
if (process.Error is not null) throw process.Error;
// Lists all filenames in the given directory.
Console.WriteLine(process.StdOut);
});
TerminalParser Class
- Namespace:
fwRelik.Terminal.Extensions
- Assembly:
fwRelik.Terminal.dll
📋 Methods
Methods | Description |
---|---|
CheckValue | Checking value in output. |
ParseToNumarationRow | Parsing the output to create a line-by-line data format. |
📄 Examples
CheckValue
const string command = "Get-ExecutionPolicy -List";
TerminalClient.Command(command, process =>
{
if (process.Error is not null) throw process.Error;
bool result = TerminalParser.CheckValue(
stdOut: process.StdOut,
keyword: "LocalMachine",
stateValue: "Unrestricted"
);
Console.WriteLine($"Local Machine Execution policy is Unrestricted: {result}");
});
If the result and the keyword are the same, then the output can be checked like this:
const string command = "Test-Path 'C:\Windows\System32'";
TerminalClient.Command(command, process =>
{
if (process.Error is not null) throw process.Error;
bool result = TerminalParser.CheckValue(
stdOut: process.StdOut,
keyword: "True",
stateValue: "True"
);
Console.WriteLine($"Local Machine Execution policy is Unrestricted: {result}");
});
In this way, it is possible to check the boolean value and much more for the complete conformity of the output.
Searching on a different line from the keyword can be done with an additional parameter of stateRow
by default it is 0
.
ParseToNumarationRow
const string command = "dir | Select-Object -Property Mode, Name";
TerminalClient.Command(command, process =>
{
if (process.Error is not null) throw process.Error;
string[] rows = TerminalParser.ParseToNumarationRow(process.StdOut);
for (int i = 0; i < rows.Length; i++)
Console.WriteLine($"[{i}] : {rows[i]}");
});
There is also the meaning of padding
. Indentation from above. Values within this range will be excluded from the list. Default value: 0
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows10.0.17763 is compatible. net7.0-windows was computed. net8.0-windows was computed. |
-
net6.0-windows10.0.17763
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on fwRelik.Terminal:
Package | Downloads |
---|---|
fwRelik.SSHSetup
Setting OpenSSH |
GitHub repositories
This package is not used by any popular GitHub repositories.