Environment.CommandLine 属性

定义

获取该进程的命令行。

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

属性值

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操作系统而异。

适用于

另请参阅