Environment.CommandLine Egenskap

Definition

Hämtar kommandoraden för den här processen.

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

Egenskapsvärde

En sträng som innehåller kommandoradsargument.

Exempel

I följande exempel visas en egen kommandorad.

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

Kommentarer

Den här egenskapen ger åtkomst till programnamnet och eventuella argument som angavs på kommandoraden när den aktuella processen startades.

Programnamnet kan innehålla sökvägsinformation, men krävs inte för att göra det. GetCommandLineArgs Använd metoden för att hämta kommandoradsinformationen parsad och lagrad i en matris med strängar.

Den maximala storleken på kommandoradsbufferten är inte inställd på ett visst antal tecken. det varierar beroende på vilket Windows operativsystem som körs på datorn.

Gäller för

Se även