Environment.GetCommandLineArgs メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Environment.GetCommandLineArgs メソッドの意味・解説 

Environment.GetCommandLineArgs メソッド

現在のプロセスに対するコマンド ライン引数を格納している文字列配列を返します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function GetCommandLineArgs
 As String()
Dim returnValue As String()

returnValue = Environment.GetCommandLineArgs
public static string[] GetCommandLineArgs
 ()
public:
static array<String^>^ GetCommandLineArgs ()
public static String[] GetCommandLineArgs ()
public static function GetCommandLineArgs
 () : String[]

戻り値
各要素にコマンド ライン引数を格納している文字列の配列。先頭の要素には実行可能ファイルの名前、それに続く 0 個以上の要素には残りのコマンド ライン引数が格納されます。

例外例外
解説解説

配列の先頭の要素には、実行中のプログラムのファイル名が格納されます。ファイル名が取得できない場合、先頭の要素は String.Empty に等しくなります。残りの要素には、コマンド ラインで入力された追加のトークンが格納されます。

プログラム ファイル名にはパス情報を含めることができますが、必須ではありません。

引用符 (QUOTATION MARK, U+0022) 内に空白が存在しない場合、コマンド ライン引数は空白 (SPACE (U+0020) または CHARACTER TABULATION (U+0009)) で区切られます。引用符内の空白は、引用符で囲まれたテキストの一部と見なされます。区切り記号は、コマンド ライン引数には含まれません。

引用符の後に続く円記号 ("\") (REVERSE SOLIDUS (U+005C)) は、特別に解釈されます。引用符の後に 2n 個の円記号 ("\") が続く場合、コマンド ライン引数には n 個の円記号が含まれ、引用符で囲まれたテキストが開始 (前のテキストが引用符で囲まれていない場合) または終了 (前のテキストが引用符で囲まれている場合) します。引用符の後に 2n+1 個の円記号 ("\") が続く場合、コマンド ライン引数には n 個の円記号とリテラルの一重引用符が含まれます。n 個の円記号 ("\") の前に引用符がない場合、コマンド ライン引数には n 個の円記号が含まれます。

コマンド ラインを単一の文字列として取得するには、CommandLine プロパティを使用します。

Windows NT 4.0, Windows 2000 プラットフォームメモ : 実行可能ファイルの名前にパスは含まれません。

Windows 98, Windows Millennium Edition プラットフォームメモ : 実行可能ファイルの名前にパスが含まれます。長いファイル名 (8.3 形式ではないファイル名) は、8.3 形式に短縮される可能性があります。

使用例使用例
' Sample for the Environment.GetCommandLineArgs method
Imports System

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 'Main
End Class 'Sample
'
'This example produces the following results:
'
'C:\>GetCommandLineArgs ARBITRARY TEXT
'
'GetCommandLineArgs: GetCommandLineArgs, ARBITRARY, TEXT
'
// 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
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 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
*/
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Environment.GetCommandLineArgs メソッド」の関連用語

Environment.GetCommandLineArgs メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Environment.GetCommandLineArgs メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS