Export (0) Print
Expand All

Environment.GetCommandLineArgs Method

Returns a string array containing the command-line arguments for the current process.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static string[] GetCommandLineArgs ()
public static String[] GetCommandLineArgs ()
public static function GetCommandLineArgs () : String[]

Return Value

An array of string where each element contains a command-line argument. The first element is the executable file name, and the following zero or more elements contain the remaining command-line arguments.

Exception typeCondition

NotSupportedException

The system does not support command-line arguments.

The first element in the array contains the file name of the executing program. If the file name is not available, the first element is equal to String.Empty. The remaining elements contain any additional tokens entered on the command line.

The program file name can, but is not required to, include path information.

Command-line arguments are delimited by white space (SPACE (U+0020) or CHARACTER TABULATION (U+0009)), unless the white space appears within quotation marks (QUOTATION MARK, U+0022). White space within quotation marks is considered part of the quoted text. The delimiter is not included in the command-line argument.

Backslash characters (REVERSE SOLIDUS (U+005C)) followed by a quotation mark are interpreted specially. If 2n backslashes are followed by a quotation mark, the command-line argument contains n backslashes, and quoted text begins if previous text was unquoted or ends if previous text was quoted. If 2n+1 backslashes are followed by a quotation mark, the command-line argument contains n backslashes and a literal quotation mark. If n backslashes are not followed by a quotation mark, the command-line argument contains n backslashes.

To obtain the command line as a single string, use the CommandLine property.

Windows NT 4.0, Windows 2000 Platform Note: The name of the executable file does not include the path.

Windows 98, Windows Millennium Edition Platform Note: The name of the executable file includes the path. Long file names (non-8dot3 names) can be shortened to their 8dot3 representation.

// Sample for the Environment.GetCommandLineArgs method
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
//  Invoke this sample with an arbitrary set of command line arguments.
    String[] arguments = Environment.GetCommandLineArgs();
    Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));
    }
}
/*
This example produces the following results:

C:\>GetCommandLineArgs ARBITRARY TEXT

GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
*/

// Sample for the Environment.GetCommandLineArgs method
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        //  Invoke this sample with an arbitrary set of command line arguments.
        String arguments[] = Environment.GetCommandLineArgs();
        Console.WriteLine("GetCommandLineArgs: {0}", 
            String.Join(", ", arguments));
    } //main
} //Sample

/*
This example produces the following results:

C:\>GetCommandLineArgs ARBITRARY TEXT

GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft