参数传输到C#控制台应用程序

时间:2013-09-09 07:37:21

标签: c#

我有简单的C#控制台应用程序:

static int Main(string[] args)
{
    Console.WriteLine("[" + args.Length + "]");
    for (int i = 0; i < args.Length; i++)
        Console.WriteLine(args[i]);
    Console.ReadKey();
}

现在我打开Windows控制台并输入:

C: &&
cd "C:\Users\yagudin.rr\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\bin\Debug\" &&
"EmailSender.exe" "C:\Users\yagudin.rr\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\bin\Debug\" "C:\Program Files (x86)\FastReports\FastReport Studio\Bin\"

输出如下:

[4]
C:\Users\yagudin.rr\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\bin\Debug" C:\Program
Files
(x86)\FastReports\FastReport
Studio\Bin"

但我想看到这个:

[2]
C:\Users\yagudin.rr\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\bin\Debug\
C:\Program Files (x86)\FastReports\FastReport Studio\Bin\

我似乎很容易,但我已经花了很多时间来寻找解决方案。谢谢。

1 个答案:

答案 0 :(得分:2)

您可以使用修补程序末尾的反斜杠(EmailSender之后和Bin之后)在命令行中转义结尾引号。
删除它们:

"EmailSender.exe" "C:\Users\yagudin.rr\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\bin\Debug" "C:\Program Files (x86)\FastReports\FastReport Studio\Bin"

如果您希望包含反斜杠,则需要在报价出现之前将其转义:

"EmailSender.exe" "C:\Users\yagudin.rr\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\bin\Debug\\" "C:\Program Files (x86)\FastReports\FastReport Studio\Bin\\"