Прочитать на английском

Поделиться через


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 операционной системы, работающей на компьютере.

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

Продукт Версии
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

См. также раздел