简体   繁体   English

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

[英]passing a newline in commandline parameter in c#

I have a console application with some arguments to be passed. 我有一个带有一些参数的控制台应用程序。

"c:\\My Folder\\myapplication.exe" /a="\\"I am passing this argument \\n my newline\\""; “ c:\\ My Folder \\ myapplication.exe” / a =“ \\”我正在传递此参数\\ n我的换行符“”;

But while executing, it discards the "my newline" as argument. 但是在执行时,它会丢弃“我的换行符”作为参数。 In my application I need this new line as a new line to be passed as a text. 在我的应用程序中,我需要此新行作为要作为文本传递的新行。

Is it possible to pass a new line character in a command line parameter. 是否可以在命令行参数中传递换行符。

I am unable to replicate your concern since you did not provide a valid sample code. 由于您没有提供有效的示例代码,因此我无法重复您的问题。

Here's a working code. 这是一个工作代码。

Program to display args: 程序显示参数:

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

            Console.ReadLine();
        }
    }
}

Program to start the process: 程序启动过程:

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();
        }
    }
}

Output: 输出:

工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM