Gapotchenko.FX.Diagnostics.CommandLine
2026.6.2
Prefix Reserved
dotnet add package Gapotchenko.FX.Diagnostics.CommandLine --version 2026.6.2
NuGet\Install-Package Gapotchenko.FX.Diagnostics.CommandLine -Version 2026.6.2
<PackageReference Include="Gapotchenko.FX.Diagnostics.CommandLine" Version="2026.6.2" />
<PackageVersion Include="Gapotchenko.FX.Diagnostics.CommandLine" Version="2026.6.2" />
<PackageReference Include="Gapotchenko.FX.Diagnostics.CommandLine" />
paket add Gapotchenko.FX.Diagnostics.CommandLine --version 2026.6.2
#r "nuget: Gapotchenko.FX.Diagnostics.CommandLine, 2026.6.2"
#:package Gapotchenko.FX.Diagnostics.CommandLine@2026.6.2
#addin nuget:?package=Gapotchenko.FX.Diagnostics.CommandLine&version=2026.6.2
#tool nuget:?package=Gapotchenko.FX.Diagnostics.CommandLine&version=2026.6.2
Overview
The module provides primitives for command line manipulation.
CommandLineBuilder
CommandLineBuilder class allows you to dynamically build a command line.
It provides the built-in support for characters than need escaping.
Semantically CommandLineBuilder is similar to StringBuilder class:
using Gapotchenko.FX.Diagnostics;
var clb = new CommandLineBuilder();
clb.AppendParameter("/b");
clb.AppendFileName(@"C:\Temp\Test 1.txt");
clb.AppendFileName(@"C:\Temp\Test 2.txt");
Console.WriteLine(clb.ToString());
The code above produces the following output:
/b "C:\Temp\Test 1.txt" "C:\Temp\Test 2.txt"
Note how some command-line parameters were automatically quoted because they contained whitespace characters.
CommandLineBuilder supports a fluent interface, just like conventional StringBuilder.
So the code can be rewritten as:
var clb = new CommandLineBuilder()
.AppendParameter("/b")
.AppendFileName(@"C:\Temp\Test 1.txt")
.AppendFileName(@"C:\Temp\Test 2.txt");
Console.WriteLine(clb.ToString());
The resulting command line can be used in various places, most notably for starting a new process:
using System.Diagnostics;
Process.Start("copy", clb.ToString());
CommandLine
CommandLine static class provides operations for command line manipulation.
Build
CommandLine.Build method allows you to quickly build a command-line string from a specified list of arguments.
Basically, this is a shortcut to CommandLineBuilder class in a handy functional form:
string commandLine = CommandLine.Build("/b", @"C:\Temp\Test 1.txt", @"C:\Temp\Test 2.txt");
Such a form is very useful in something like this:
Process.Start(
"cmd",
CommandLine.Build(
"/C", "copy",
"/b", @"C:\Temp\Test 1.txt", @"C:\Temp\Test 2.txt"));
Another cool thing: if you want to exclude some arguments from the command line then you can just make them null:
// 'mode' will have a non-null value if there is a need to specify it.
string? mode = binary ? "/b" : null;
string commandLine = CommandLine.Build(mode, @"C:\Temp\Test 1.txt", @"C:\Temp\Test 2.txt");
Console.WriteLine(commandLine);
The code above produces the following outputs depending on the value of binary flag:
"C:\Temp\Test 1.txt" "C:\Temp\Test 2.txt"
/b "C:\Temp\Test 1.txt" "C:\Temp\Test 2.txt"
This is a neat departure from a traditional .NET convention where it always throws ArgumentNullException.
Instead, Gapotchenko.FX uses a slightly different philosophy.
It does the best job possible under existing conditions by following common-sense expectations.
Split
CommandLine.Split provides the inverse operation to CommandLine.Build.
It allows you to split a command-line string into a list of arguments using the rules of a host operating system:
using Gapotchenko.FX.Diagnostics;
string commandLine = "/b \"C:\\Temp\\Test 1.txt\" \"C:\\Temp\\Test 2.txt\"";
foreach (string arg in CommandLine.Split(commandLine))
Console.WriteLine(arg);
The code above produces the following output:
/b
C:\Temp\Test 1.txt
C:\Temp\Test 2.txt
CommandShell
CommandShell static class from Gapotchenko.FX.Diagnostics.CommandLine module provides operations for locating files using the PATH environment variable according to the rules of a host operating system.
Where
The Where method enumerates the paths of a file with the specified name using the PATH environment variable. It is similar to the Windows where command or Unix which command, but works cross-platform.
The basic usage is straightforward:
using Gapotchenko.FX.Diagnostics;
foreach (string path in CommandShell.Where("notepad"))
Console.WriteLine(path);
On Windows, this might produce output like:
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
The method respects the operating system's file discovery rules:
- On Windows, it uses the
PATHEXTenvironment variable to try different file extensions (.exe,.cmd,.bat, etc.) - On Unix-like systems, it searches for files with the exact name specified
- It handles case sensitivity according to the host operating system
Where with Probing Paths
You can also specify custom probing paths that will be checked before the PATH environment variable:
using Gapotchenko.FX.Diagnostics;
// Check custom directories first, then PATH
string[] customPaths = [@"C:\MyTools", @"C:\MyDir"];
foreach (string path in CommandShell.Where("myapp", customPaths))
Console.WriteLine(path);
This is useful when you want to prioritize certain directories or check additional locations beyond the standard PATH.
Handling Paths with Directory Information
If the file name contains directory information, Where method will only search in that specific directory:
using Gapotchenko.FX.Diagnostics;
// Only searches in "C:\MyDir" directory
foreach (string path in CommandShell.Where(@"C:\MyDir\myapp"))
Console.WriteLine(path);
Cross-Platform Behavior
The Where method automatically adapts to the host operating system:
- On Windows: uses
PATHEXTenvironment variable to try multiple file extensions - On Unix/Linux/macOS: searches for files with the exact name specified
This makes it easy to write cross-platform code that locates executable files correctly on any operating system.
Commonly Used Types
Gapotchenko.FX.Diagnostics.CommandLineGapotchenko.FX.Diagnostics.CommandLineBuilderGapotchenko.FX.Diagnostics.CommandShell
Other Modules
Let's continue with a look at some other modules provided by Gapotchenko.FX:
- Gapotchenko.FX
- Gapotchenko.FX.AppModel.Information
- Gapotchenko.FX.Collections
- Gapotchenko.FX.Console
- Gapotchenko.FX.Data
- Gapotchenko.FX.Diagnostics
- Gapotchenko.FX.IO
- Gapotchenko.FX.Linq
- Gapotchenko.FX.Math
- Gapotchenko.FX.Memory
- Gapotchenko.FX.Security.Cryptography
- Gapotchenko.FX.Text
- Gapotchenko.FX.Threading
- Gapotchenko.FX.Tuples
- Gapotchenko.FX.Versioning
Or look at the full list of modules.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- Gapotchenko.FX (>= 2026.6.2)
- Gapotchenko.FX.IO (>= 2026.6.2)
- Gapotchenko.FX.Text (>= 2026.6.2)
-
.NETStandard 2.0
- Gapotchenko.FX (>= 2026.6.2)
- Gapotchenko.FX.IO (>= 2026.6.2)
- Gapotchenko.FX.Text (>= 2026.6.2)
-
.NETStandard 2.1
- Gapotchenko.FX (>= 2026.6.2)
- Gapotchenko.FX.IO (>= 2026.6.2)
- Gapotchenko.FX.Text (>= 2026.6.2)
-
net10.0
- Gapotchenko.FX (>= 2026.6.2)
- Gapotchenko.FX.IO (>= 2026.6.2)
- Gapotchenko.FX.Text (>= 2026.6.2)
-
net8.0
- Gapotchenko.FX (>= 2026.6.2)
- Gapotchenko.FX.IO (>= 2026.6.2)
- Gapotchenko.FX.Text (>= 2026.6.2)
-
net9.0
- Gapotchenko.FX (>= 2026.6.2)
- Gapotchenko.FX.IO (>= 2026.6.2)
- Gapotchenko.FX.Text (>= 2026.6.2)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Gapotchenko.FX.Diagnostics.CommandLine:
| Package | Downloads |
|---|---|
|
Gapotchenko.FX.Diagnostics.Process
Provides extended functionality for process manipulation. |
|
|
Gapotchenko.FX.Profiles.Core
Represents the Core profile of Gapotchenko.FX toolkit. |
|
|
Gapotchenko.FX.Diagnostics.WebBrowser
Provides high-level integration with OS web browser. |
|
|
Gapotchenko.Shields.Microsoft.Wsl.Deployment
Locates setup instances of Windows Subsystem for Linux (WSL). |
|
|
Gapotchenko.Shields.Canonical.Snap.Resolution
The resolution module of the Gapotchenko Shield for Canonical Snap. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.2 | 47 | 3/29/2026 |
| 2026.5.3 | 495 | 2/24/2026 |
| 2026.4.2 | 415 | 2/4/2026 |
| 2026.3.5 | 352 | 1/29/2026 |
| 2026.2.2 | 2,511 | 1/25/2026 |
| 2026.1.5 | 325 | 1/13/2026 |
| 2025.1.45 | 2,792 | 12/25/2025 |
| 2025.1.27-beta | 425 | 10/8/2025 |
| 2025.1.26-beta | 453 | 8/30/2025 |
| 2025.1.25-beta | 1,155 | 7/22/2025 |
| 2025.1.24-beta | 596 | 7/16/2025 |
| 2025.1.23-beta | 465 | 7/12/2025 |
| 2024.2.5 | 24,714 | 12/31/2024 |
| 2024.1.3 | 5,092 | 11/10/2024 |
| 2022.2.7 | 65,677 | 5/1/2022 |
| 2022.2.5 | 2,153 | 5/1/2022 |
| 2022.1.4 | 1,205 | 4/6/2022 |
| 2021.2.21 | 1,329 | 1/21/2022 |
| 2021.2.20 | 1,210 | 1/17/2022 |