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 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 作業系統而有所不同。

適用於

另請參閱