Environment.GetCommandLineArgs 메서드

정의

현재 프로세스에 대한 명령줄 인수가 포함된 문자열 배열을 반환합니다.

public:
 static cli::array <System::String ^> ^ GetCommandLineArgs();
public static string[] GetCommandLineArgs ();
static member GetCommandLineArgs : unit -> string[]
Public Shared Function GetCommandLineArgs () As String()

반환

String[]

각 요소에 명령줄 인수가 포함된 문자열의 배열입니다. 첫 번째 요소는 실행 파일 이름이며 다음에 나오는 0개 이상의 요소에는 나머지 명령줄 인수가 들어 있습니다.

예외

시스템에서 명령줄 인수를 지원하지 않습니다.

예제

다음 예제에서는 애플리케이션의 명령줄 인수가 표시 됩니다.

using namespace System;

int main()
{
   Console::WriteLine();
   
   //  Invoke this sample with an arbitrary set of command line arguments.
   array<String^>^ arguments = Environment::GetCommandLineArgs();
   Console::WriteLine( "GetCommandLineArgs: {0}", String::Join( ", ", arguments ) );
}
/*
This example produces output like the following:
    
    C:\>GetCommandLineArgs ARBITRARY TEXT
    
      GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
*/
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 output like the following:

    C:\>GetCommandLineArgs ARBITRARY TEXT

      GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
*/
open System

//  Invoke this sample with an arbitrary set of command line arguments.
let arguments = Environment.GetCommandLineArgs()

String.concat ", " arguments
|> printfn "\nGetCommandLineArgs: %s"

// This example produces output like the following:
//     C:\>GetCommandLineArgs ARBITRARY TEXT
//
//       GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      '  Invoke this sample with an arbitrary set of command line arguments.
      Dim arguments As String() = Environment.GetCommandLineArgs()
      Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments))
   End Sub
End Class
'This example produces output like the following:
'    
'    C:\>GetCommandLineArgs ARBITRARY TEXT
'    
'      GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
'

설명

배열의 첫 번째 요소에는 실행 중인 프로그램의 파일 이름이 포함됩니다. 파일 이름을 사용할 수 없는 경우 첫 번째 요소는 와 같습니다 String.Empty. 나머지 요소에는 명령줄에 입력된 추가 토큰이 포함됩니다.

.NET 5 이상 버전에서 단일 파일 게시의 경우 첫 번째 요소는 호스트 실행 파일의 이름입니다.

프로그램 파일 이름은 경로 정보를 포함할 수 있지만 필요하지는 않습니다.

명령줄 인수는 공백으로 구분됩니다. 큰따옴표(")를 사용하여 인수 내에 공백을 포함할 수 있습니다. 그러나 작은따옴표(')는 이 기능을 제공하지 않습니다.

큰따옴표가 두 개 또는 짝수 백슬래시를 따르는 경우 각 진행 백슬래시 쌍은 하나의 백슬래시로 대체되고 큰따옴표는 제거됩니다. 큰따옴표가 홀수 백슬래시(단 하나만 포함)를 따르는 경우 앞의 각 쌍은 하나의 백슬래시로 대체되고 나머지 백슬래시는 제거됩니다. 그러나 이 경우 큰따옴표는 제거되지 않습니다.

다음 표는 명령줄 인수 구분 수 있는 방법을 보여 주고 가정 MyApp 현재 실행 중인 애플리케이션으로 합니다.

명령줄의 입력 결과 명령줄 인수
MyApp alpha beta MyApp, alpha, beta
MyApp "alpha with spaces" "beta with spaces" MyApp, alpha with spaces, beta with spaces
MyApp 'alpha with spaces' beta MyApp, 'alpha, with, spaces', beta
MyApp \\\alpha \\\\"beta MyApp, \\\alpha, \\beta
MyApp \\\\\"alpha \"beta MyApp, \\"alpha, "beta

명령줄을 단일 문자열로 가져오려면 속성을 사용합니다 CommandLine .

적용 대상

추가 정보