Environment.CommandLine Propriété

Définition

Obtient la ligne de commande de ce processus.

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

Valeur de propriété

Chaîne contenant des arguments de ligne de commande.

Exemples

L’exemple suivant affiche sa propre ligne de commande.

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

Remarques

Cette propriété fournit l’accès au nom du programme et à tous les arguments spécifiés sur la ligne de commande lorsque le processus actuel a été démarré.

Le nom du programme peut inclure des informations de chemin d’accès, mais il n’est pas nécessaire de le faire. Utilisez la GetCommandLineArgs méthode pour récupérer les informations de ligne de commande analysées et stockées dans un tableau de chaînes.

La taille maximale de la mémoire tampon de ligne de commande n’est pas définie sur un nombre spécifique de caractères ; il varie en fonction du système d’exploitation Windows qui s’exécute sur l’ordinateur.

S’applique à

Voir aussi