【问题标题】:passing a newline in commandline parameter in c#在 C# 的命令行参数中传递换行符
【发布时间】:2023-03-18 00:45:02
【问题描述】:

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

"c:\My Folder\myapplication.exe" /a="\"我正在传递这个参数\n my newline\"";

但在执行时,它会丢弃“我的换行符”作为参数。在我的应用程序中,我需要将这一新行作为新行作为文本传递。

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

【问题讨论】:

  • 你能详细说明一下你是如何处理步骤的吗? @satyajit

标签: c# command-line command-line-arguments


【解决方案1】:

由于您没有提供有效的示例代码,我无法重现您的担忧。

这是一个有效的代码。

显示参数的程序:

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

输出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    • 2016-12-28
    • 2012-07-11
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    相关资源
    最近更新 更多