在 C# 的命令行参数中传递一个换行符

passing a newline in commandline parameter in c#

我有一个控制台应用程序,需要传递一些参数。

"c:\My Folder\myapplication.exe" /a="\"I am passing this argument \n my newline\"";

但是在执行时,它丢弃了 "my newline" 作为参数。在我的应用程序中,我需要这个新行作为一个新行作为文本传递。

是否可以在命令行参数中传递换行符

由于您没有提供有效的示例代码,我无法复制您的问题。

这是一个工作代码。

显示参数的程序:

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach(string s in args)
            {
                Console.WriteLine(s);
            }

            Console.ReadLine();
        }
    }
}

启动进程的程序:

namespace ConsoleApplication1
{
    public class Program
    {
        static void Main()
        {
            Process process = new Process();

            // Configure the process using the StartInfo properties.
            process.StartInfo.FileName = @"C:\Users\tugadoje\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\bin\Debug\ConsoleApplication2.exe";
            process.StartInfo.Arguments = "\"I am passing this argument \n my newline\"";
            process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
            process.Start();
            process.WaitForExit();// Waits here for the process to exit.

            Console.Read();
        }
    }
}

输出: