ProcessStartInfo.Arguments ProcessStartInfo.Arguments ProcessStartInfo.Arguments ProcessStartInfo.Arguments Property

定義

アプリケーションを起動するときに使用するコマンド ライン引数のセットを取得または設定します。Gets or sets the set of command-line arguments to use when starting the application.

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

プロパティ値

FileName プロパティで指定したターゲット アプリケーションに渡す引数を格納した単一の文字列。A single string containing the arguments to pass to the target application specified in the FileName property. 既定値は、空の文字列 ("") です。The default is an empty string ("").

最初の例では、コンソールに引数を表示する小規模なアプリケーション (argsecho) を作成します。The first example creates a small application (argsecho.exe) that echos its arguments to the console. 2番目の例では、argsecho を呼び出してArgumentsプロパティのさまざまなバリエーションを示すアプリケーションを作成します。The second example creates an application that invokes argsecho.exe to demonstrate different variations for the Arguments property.

// 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プロパティに割り当てられた文字列の長さは、32699未満である必要があります。The length of the string assigned to the Arguments property must be less than 32,699.

引数はターゲット アプリケーションで解析され、解釈されるため、そのアプリケーションの想定に合わせたものでなければなりません。Arguments are parsed and interpreted by the target application, so must align with the expectations of that application. 次の例に示すように、.NET アプリケーションの場合、スペースは複数の引数間の区切り記号として解釈されます。For .NET applications as demonstrated in the Examples below, spaces are interpreted as a separator between multiple arguments. 1 つの引数にスペースが含まれる場合は引用符で囲む必要がありますが、これらの引用符はターゲット アプリケーションに渡されません。A single argument that includes spaces must be surrounded by quotation marks, but those quotation marks are not carried through to the target application. 最後に解析された引数に引用符を含めるには、各マークをトリプルエスケープします。To include quotation marks in the final parsed argument, triple-escape each mark. このプロパティを使用してコマンドライン引数を設定するArgumentList場合は、に要素を含めることはできません。If you use this property to set command-line arguments, ArgumentList must not contain any elements.

ArgumentsArgumentListは、.net Core 2.1 以降でサポートされており、.NET Standard 2.1 からは独立しています。Arguments and ArgumentList, which is supported starting with .NET Core 2.1 and .NET Standard 2.1, are independent of one another. つまり、 Argumentsプロパティに割り当てられた文字列はArgumentListコレクションに設定されず、 ArgumentListコレクションのメンバーはArgumentsプロパティに割り当てられません。That is, the string assigned to the Arguments property does not populate the ArgumentList collection, and the members of the ArgumentList collection are not assigned to the Arguments property.

適用対象