Redigera

Dela via


ProcessStartInfo.ArgumentList Property

Definition

Gets a collection of command-line arguments to use when starting the application. Strings added to the list don't need to be previously escaped.

public:
 property System::Collections::ObjectModel::Collection<System::String ^> ^ ArgumentList { System::Collections::ObjectModel::Collection<System::String ^> ^ get(); };
public System.Collections.ObjectModel.Collection<string> ArgumentList { get; }
member this.ArgumentList : System.Collections.ObjectModel.Collection<string>
Public ReadOnly Property ArgumentList As Collection(Of String)

Property Value

A collection of command-line arguments.

Examples

This example adds three arguments to the process start info.

var info = new System.Diagnostics.ProcessStartInfo("cmd.exe")
{
    ArgumentList = {
        "/c",
        "dir",
        @"C:\Program Files\dotnet" // The space character is escaped automatically.
    }
};

// The corresponding assignment to the Arguments property is:
var info = new System.Diagnostics.ProcessStartInfo("cmd.exe")
{
    Arguments = "/c dir \"C:\\Program Files\\dotnet\""
};
Dim info As New System.Diagnostics.ProcessStartInfo("cmd.exe")
info.ArgumentList.Add("/c")
info.ArgumentList.Add("dir")
info.ArgumentList.Add("C:\Program Files\dotnet")

' The corresponding assignment to the Arguments property is:
info.Arguments = "/c dir ""C:\Program Files\dotnet"""

Remarks

ArgumentList and the Arguments property are independent of one another and only one of them can be used at the same time. The main difference between these APIs is that ArgumentList escapes the provided arguments and internally builds a single string that's passed to the operating system when calling Process.Start(info). So if you aren't sure how to properly escape your arguments, you should choose ArgumentList over Arguments.

Important

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.

Applies to