Environment.CommandLine Właściwość

Definicja

Pobiera wiersz polecenia dla tego procesu.

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

Wartość właściwości

String

Ciąg zawierający argumenty wiersza polecenia.

Przykłady

Poniższy przykład przedstawia własny wiersz polecenia.

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

Uwagi

Ta właściwość zapewnia dostęp do nazwy programu i wszystkich argumentów określonych w wierszu polecenia po uruchomieniu bieżącego procesu.

Nazwa programu może zawierać informacje o ścieżce, ale nie jest to wymagane. GetCommandLineArgs Użyj metody , aby pobrać informacje wiersza polecenia analizowane i przechowywane w tablicy ciągów.

Maksymalny rozmiar buforu wiersza polecenia nie jest ustawiony na określoną liczbę znaków; różni się w zależności od systemu operacyjnego Windows, który jest uruchomiony na komputerze.

Dotyczy

Zobacz też