ProcessStartInfo.Arguments Свойство

Определение

Получает или задает набор аргументов командной строки, используемых при запуске приложения.

public:
 property System::String ^ Arguments { System::String ^ get(); void set(System::String ^ value); };
public string Arguments { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }
[System.ComponentModel.SettingsBindable(true)]
public string Arguments { get; set; }
member this.Arguments : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Arguments : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Arguments : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Arguments : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
member this.Arguments : string with get, set
Public Property Arguments As String

Значение свойства

Одна строка, содержащая аргументы для передачи в целевое приложение, указанное в свойстве FileName. Значение по умолчанию — пустая строка ("").

Атрибуты

Примеры

В первом примере создается небольшое приложение (argsecho.exe), которое передает свои аргументы в консоль. Во втором примере создается приложение, которое вызывает argsecho.exe для демонстрации Arguments различных вариантов свойства .

// Place this code into a console project called ArgsEcho to build the argsecho.exe target

using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine("Received the following arguments:\n");

    for (int i = 0; i < args->Length; i++)
    {
        Console::WriteLine("[" + i + "] = " + args[i]);
    }

    Console::WriteLine("\nPress any key to exit");
    Console::ReadLine();
    return 0;
}
// Place this code into a console project called ArgsEcho to build the argsecho.exe target

using System;

namespace StartArgs
{
    class ArgsEcho
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Received the following arguments:\n");

            for (var i = 0; i < args.Length; i++)
            {
                Console.WriteLine($"[{i}] = {args[i]}");
            }

            Console.WriteLine("\nPress any key to exit");
            Console.ReadLine();
        }
    }
}
' Place this code into a console project called ArgsEcho to build the argsecho.exe target

Module Module1
    Sub Main()
        Dim i As Integer = 0

        For Each s As String In My.Application.CommandLineArgs
            Console.WriteLine($"[{i}] = {s}")
            i = i + 1
        Next

        Console.WriteLine(Environment.NewLine + "Press any key to exit")
        Console.ReadLine()
    End Sub
End Module
// Place the following code into a console project called StartArgsEcho. It depends on the
// console application named argsecho.exe.

using namespace System;
using namespace System::Diagnostics;

int main()
{
    ProcessStartInfo^ startInfo = gcnew ProcessStartInfo("argsecho.exe");
    startInfo->WindowStyle = ProcessWindowStyle::Normal;

    // Start with one argument.
    // Output of ArgsEcho:
    //  [0]=/a            
    startInfo->Arguments = "/a";
    Process::Start(startInfo);

    // Start with multiple arguments separated by spaces.
    // Output of ArgsEcho:
    //  [0] = /a
    //  [1] = /b
    //  [2] = c:\temp
    startInfo->Arguments = "/a /b c:\\temp";
    Process::Start(startInfo);

    // An argument with spaces inside quotes is interpreted as multiple arguments.
    // Output of ArgsEcho:
    //  [0] = /a
    //  [1] = literal string arg
    startInfo->Arguments = "/a \"literal string arg\"";
    Process::Start(startInfo);

    // An argument inside double quotes is interpreted as if the quote weren't there,
    // that is, as separate arguments. 
    // Output of ArgsEcho:
    //  [0] = /a
    //  [1] = /b:string
    //  [2] = in
    //  [3] = double
    //  [4] = quotes
    startInfo->Arguments = "/a /b:\"\"string in double quotes\"\"";
    Process::Start(startInfo);

    // Triple-escape quotation marks to include the character in the final argument received
    // by the target process.
    //  [0] = /a
    //  [1] = /b:"quoted string"
    startInfo->Arguments = "/a /b:\"\"\"quoted string\"\"\"";
    Process::Start(startInfo);

    return 0;
}
// Place this code into a console project called StartArgsEcho. It depends on the
// console application named argsecho.exe.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace StartArgsEcho
{
    class Program
    {
        static void Main()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("argsecho.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Normal;

            // Start with one argument.
            // Output of ArgsEcho:
            //  [0]=/a
            startInfo.Arguments = "/a";
            Process.Start(startInfo);

            // Start with multiple arguments separated by spaces.
            // Output of ArgsEcho:
            //  [0] = /a
            //  [1] = /b
            //  [2] = c:\temp
            startInfo.Arguments = "/a /b c:\\temp";
            Process.Start(startInfo);

            // An argument with spaces inside quotes is interpreted as multiple arguments.
            // Output of ArgsEcho:
            //  [0] = /a
            //  [1] = literal string arg
            startInfo.Arguments = "/a \"literal string arg\"";
            Process.Start(startInfo);

            // An argument inside double quotes is interpreted as if the quote weren't there,
            // that is, as separate arguments. Equivalent verbatim string is @"/a /b:""string with quotes"""
            // Output of ArgsEcho:
            //  [0] = /a
            //  [1] = /b:string
            //  [2] = in
            //  [3] = double
            //  [4] = quotes
            startInfo.Arguments = "/a /b:\"\"string in double quotes\"\"";
            Process.Start(startInfo);

            // Triple-escape quotation marks to include the character in the final argument received
            // by the target process. Equivalent verbatim string: @"/a /b:""""""quoted string""""""";
            //  [0] = /a
            //  [1] = /b:"quoted string"
            startInfo.Arguments = "/a /b:\"\"\"quoted string\"\"\"";
            Process.Start(startInfo);
        }
    }
}
' Place this code into a console project called StartArgsEcho. It depends on the
' console application named argsecho.exe.

Module Module1
    Sub Main()
        Dim startInfo As ProcessStartInfo = New ProcessStartInfo("argsecho.exe")
        startInfo.WindowStyle = ProcessWindowStyle.Normal

        ' Start with one argument.
        ' Output of ArgsEcho:
        '  [0]=/a            
        startInfo.Arguments = "/a"
        Process.Start(startInfo)

        ' Start with multiple arguments separated by spaces.
        ' Output of ArgsEcho:
        '  [0] = /a
        '  [1] = /b
        '  [2] = c:\temp
        startInfo.Arguments = "/a /b c:\temp"
        Process.Start(startInfo)

        ' An argument with spaces inside quotes is interpreted as multiple arguments.
        ' Output of ArgsEcho:
        '  [0] = /a
        '  [1] = literal string arg
        startInfo.Arguments = "/a ""literal string arg"" "
        Process.Start(startInfo)

        ' An argument inside double quotes is interpreted as if the quote weren't there,
        ' that is, as separate arguments.
        ' Output of ArgsEcho:
        '  [0] = /a
        '  [1] = /b:string
        '  [2] = in
        '  [3] = double
        '  [4] = quotes
        startInfo.Arguments = "/a /b:""""string in double quotes"""" "
        Process.Start(startInfo)

        ' Triple-escape quotation marks to include the character in the final argument received
        ' by the target process. 
        '  [0] = /a
        '  [1] = /b:"quoted string"
        startInfo.Arguments = "/a /b:""""""quoted string"""""" "
        Process.Start(startInfo)
    End Sub
End Module

Комментарии

Длина строки, назначенной свойству Arguments , должна быть меньше 32 699.

Аргументы анализируются и интерпретируются целевым приложением, поэтому они должны соответствовать ожидаемым аргументам приложения. Для приложений .NET, как показано в примерах ниже, пробелы интерпретируются как разделитель между несколькими аргументами. Одиночный аргумент, включающий пробелы, должен быть заключен в кавычки, но кавычки не указываются в целевом приложении. Чтобы включить кавычки в окончательный проанализированный аргумент, тройной экранируйте каждую метку. Если вы используете это свойство для задания аргументов командной строки, ArgumentList не должно содержать никаких элементов.

Arguments и ArgumentList, которые поддерживаются начиная с .NET Core 2.1 и .NET Standard 2.1, не зависят друг от друга. То есть строка, назначенная свойству Arguments , не заполняет коллекцию ArgumentList , а члены ArgumentList коллекции не назначаются свойству Arguments .

Важно!

Использование экземпляра этого объекта с ненадежными данными представляет угрозу безопасности. Используйте этот объект только с надежными данными. Дополнительные сведения см. в разделе Проверка всех входных данных.

Применяется к