WinArgv 1.1.0-dev-28
See the version list below for details.
dotnet add package WinArgv --version 1.1.0-dev-28
NuGet\Install-Package WinArgv -Version 1.1.0-dev-28
<PackageReference Include="WinArgv" Version="1.1.0-dev-28" />
paket add WinArgv --version 1.1.0-dev-28
#r "nuget: WinArgv, 1.1.0-dev-28"
// Install WinArgv as a Cake Addin #addin nuget:?package=WinArgv&version=1.1.0-dev-28&prerelease // Install WinArgv as a Cake Tool #tool nuget:?package=WinArgv&version=1.1.0-dev-28&prerelease
nuget.org: petrsnd/WinArgv
WinArgv
Windows command line generation from a standard args array (POSIX argv style)
Background
The .NET Framework's Process.Start()
method receives all
arguments in a single string to launch an executable. This is the case no matter which overload you call:
or, even if you use a ProcessStartInfo:
Process.Start(ProcessStartInfo)
This places the burden on the caller for escaping and quoting to ensure that args array is properly formed for the Main() method of
the executable launched by Process.Start()
.
This seems easy until there are lots of quotes, spaces, and non-standard characters in your arguments. The purpose
of this project is to allow the caller to build the array of arguments just as they expect them to be received by the called
executable. This library will build the properly escaped and quoted argument string to pass to Process.Start(). It will also generate
a ProcessStartInfo
with the FileName
and Arguments
fields filled out, and you can customize the rest from there.
Even though this is a simple library, this isn't a problem that should have to be solved by every developer who would like to create a process.
Example Usage
This library provides a way to build up process arguments in an array, similar to what would be used for execv()
. However, the
executable should be placed at index 0, so really it is more like what you would see in the argv array in main()
on a POSIX system.
var argv = new List<string> {@"C:\bin\grandmaster-flash.exe", "don't push me cuz I'm close to the edge", "I'm trying not to lose my head'"};
// create a ProcessStartInfo
var startInfo = ArgvParser.GetProcessStartInfo(argv);
// or, a commandLine
var cmdLine = ArgvParser.GetCommandLine(argv);
Console.WriteLine(cmdLine.Executable);
Console.WriteLine(cmdLine.Arguments);
The argument string may look very strange, but that is because Windows argument string parsing IS strange. It will always parse out as exactly the list of arguments you wanted to send.
You can clone this code and run the OldFrameworkTest project for an interactive demo.
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 was computed. 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. |
.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 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. 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. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0-dev-32 | 74 | 10/3/2024 |
1.1.0-dev-28 | 71 | 10/3/2024 |
1.1.0-dev-25 | 126 | 7/5/2023 |
1.1.0-dev-24 | 166 | 6/7/2022 |
1.1.0-dev-22 | 237 | 6/17/2021 |
1.0.1 | 81 | 10/3/2024 |
1.0.0 | 413 | 6/17/2021 |
1.0.0-dev-18 | 238 | 6/17/2021 |
0.9.11 | 1,141 | 9/29/2017 |
0.9.8 | 992 | 5/8/2017 |
Initial .NET Standard release. Previously only available for .NET Framework.
Creating a command line programmatically to execute a program with a complicated argument list should not be a difficult problem.
However, Windows places this burden on the programmer. Instead of just allowing programmers to construct an array with exactly
the arguments they want to appear in the argument array of Main(), Windows programmers need to know how to properly escape the
entire argument list as a string.
Use WinArgv, and don't get burned by spaces, escaping, and quoting. Generate Windows and argument string, command line, or
ProcessStartInfo to pass to Process.Start().