Environment.GetCommandLineArgs 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 프로세스에 대한 명령줄 인수를 포함하는 문자열 배열을 반환합니다.
public:
static cli::array <System::String ^> ^ GetCommandLineArgs();
public static string[] GetCommandLineArgs();
static member GetCommandLineArgs : unit -> string[]
Public Shared Function GetCommandLineArgs () As String()
반품
각 요소에 명령줄 인수가 포함된 문자열 배열입니다. 첫 번째 요소는 실행 파일 이름이며, 다음 0개 이상의 요소에는 나머지 명령줄 인수가 포함됩니다.
예외
시스템은 명령줄 인수를 지원하지 않습니다.
예제
다음 예제에서는 애플리케이션의 명령줄 인수를 표시합니다.
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 .