小编Fab*_*Fab的帖子

使用.BAT中的.application文件类型运行ac#Console App

我已经创建了一个可以读取命令参数的控制台应用程序(使用Visual Studio 2010).

当我调试时,我解析一些在Project-> [project name] Properties ... - > Debug - > Command line arguments中设置的测试参数:

它读作:"parametername1 | parametervalue1""parametername2 | parametervalue2""parametername3 | parametervalue3"

我使用以下代码来读取参数:

for (Int16 argumentsCount = 0; argumentsCount < args.Length; argumentsCount++)
{
    String[] parameterItem = args[argumentsCount].Split('|');
    String parameterName = parameterItem[0].ToString();
    String parameterValue = parameterItem[1].ToString();
    /*code continues*/

}
Run Code Online (Sandbox Code Playgroud)

当我在调试模式下运行应用程序时它工作得很好并且所有参数都被读取.

然后我将应用程序发布到服务器并确保它安装了正确的权限(为了演示的目的,我们说它在C:\ MyApp上,并且Complied代码驻留在MyApp.application中)

然后我创建了一个执行应用程序的批处理脚本.*.BAT包含以下命令:

"C:\MyApp\MyApp.application" "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"
Run Code Online (Sandbox Code Playgroud)

当我运行批处理时,这种工作就像应用程序一样...但是......我的应用程序没有收到任何参数.我知道这是因为我重新编译并发布了一些代码来读取接收的参数数量:

Console.Write("Arguments " + args.Length.ToString());
Run Code Online (Sandbox Code Playgroud)

并显示参数:0

有人可以告诉我如何编写我的批处理脚本来运行应用程序并解析我的参数/命令行参数.

c# console batch-file console-application command-line-arguments

5
推荐指数
1
解决办法
2691
查看次数