Environment.CommandLine プロパティ

定義

このプロセス用のコマンド ラインを取得します。

public:
 static property System::String ^ CommandLine { System::String ^ get(); };
public static string CommandLine { get; }
static member CommandLine : string
Public Shared ReadOnly Property CommandLine As String

プロパティ値

コマンド ラインの引数を格納している文字列。

次の例では、独自のコマンド ラインを表示します。

using namespace System;

int main()
{
   Console::WriteLine();
   
   //  Invoke this sample with an arbitrary set of command line arguments.
   Console::WriteLine( "CommandLine: {0}", Environment::CommandLine );
}
/*
The example displays output like the following:

C:\>env0 ARBITRARY TEXT

CommandLine: env0 ARBITRARY TEXT
*/
using System;

class Example
{
    public static void Main()
    {
       Console.WriteLine();
       //  Invoke this sample with an arbitrary set of command line arguments.
       Console.WriteLine("CommandLine: {0}", Environment.CommandLine);
    }
}
// The example displays output like the following:
//       C:\>env0 ARBITRARY TEXT
//
//       CommandLine: env0 ARBITRARY TEXT
open System

//  Invoke this sample with an arbitrary set of command line arguments.
printfn $"\nCommandLine: {Environment.CommandLine}"
// The example displays output like the following:
//       C:\>env0 ARBITRARY TEXT
//
//       CommandLine: env0 ARBITRARY TEXT
Class Example
   Public Shared Sub Main()
      Console.WriteLine()
      '  Invoke this sample with an arbitrary set of command line arguments.
      Console.WriteLine("CommandLine: {0}", Environment.CommandLine)
   End Sub 
End Class 
' The example displays output like the following:
'       C:\>CommandLine ARBITRARY TEXT
'       
'       CommandLine: CommandLine ARBITRARY TEXT

注釈

このプロパティは、プログラム名と、現在のプロセスが開始されたときにコマンド ラインで指定された引数へのアクセスを提供します。

プログラム名にはパス情報を含めることができますが、これを行う必要はありません。 メソッドを GetCommandLineArgs 使用して、解析され、文字列の配列に格納されたコマンド ライン情報を取得します。

コマンド ライン バッファーの最大サイズは、特定の文字数に設定されていません。これは、コンピューターで実行されている Windows オペレーティング システムによって異なります。

適用対象

こちらもご覧ください