Environment.GetCommandLineArgs 方法
2013-08-21 23:54
393 查看
返回包含当前进程的命令行参数的字符串数组。
命名空间: System程序集: mscorlib(在 mscorlib.dll 中)
语法
C#
C++
F#
VB
public static string[] GetCommandLineArgs()
返回值
类型:System.String[]字符串数组,其中的每个元素都包含一个命令行参数。 第一个元素是可执行文件名,后面的零个或多个元素包含其余的命令行参数。
异常
异常 | 条件 |
---|---|
NotSupportedException | 系统不支持命令行参数。 |
数组中的第一个元素包含执行程序的文件名。 如果该文件名不可用,则第一个元素等于 String.Empty。 其他元素包含在命令行输入的任何附加标记。
程序文件名可以(但不是必须)包含路径信息。
命令行参数由空格分隔。 可以使用双引号 (") 在参数中包含空格。 但是,单引号 (') 不提供此功能。
如果两个或偶数个反斜杠后跟双引号,则前面的每个反斜杠对被一个反斜杠替代,并且双引号被删除。 如果奇数个(包括仅仅一个)反斜杠后跟双引号,则前面的每个反斜杠对被一个反斜杠替代,其余的反斜杠被删除;但在此情况下,双引号不会被删除。
下表显示如何分隔命令行参数,并假定 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 |
平台说明:可执行文件的名称不包含该路径。
平台说明:可执行文件的名称包含该路径。 长文件名(非 8.3 名称)可以缩短到它们的 8.3 表示形式。
示例
下面的示例显示应用程序的命令行参数。
C#
C++
VB
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 */
相关文章推荐
- C# 使用 Environment.GetCommandLineArgs 方法 制作*.exe和参数 供其他程序调用
- C# 使用 Environment.GetCommandLineArgs 方法 制作*.exe和参数 供其他程序调用
- Environment.GetCommandLineArgs 方法
- [tip: commandline argument]Environment.GetCommandLineArgs
- Environment.GetCommandLineArgs();
- 转载 C#文件中GetCommandLineArgs()
- The linux command line--part Two Configuration And The Environment
- ubuntu 14.04 编译android4.0 出现gcc-version.sh: line 11: cc: command not found错误解决方法
- C++ cin.get()和cin.getline()方法详解及区别
- C#中如何获取其他进程的命令行参数 ( How to get other processes's command line argument )
- Mysql 5.6 command line Client闪退的解决方法
- GetCommandLine [API]
- How do I get a MAC address via command line?
- GetCommandLine 获取当前进程的命令行字符串 对字符串进行分割
- Android获取TextView行数方法getLineCount()返回值为0
- C++基础:各种输入方法总结,cin、cin.get()、cin.getline()、getline()、gets()、getchar()
- c++ ---------命令行获得和转换文件CommandLineToArgvW和GetCommandLineW()的使用
- mysql command line client和mysql.exe输入密码后闪退问题解决方法
- 老生常谈C++getline使用方法