【问题标题】:Greater than (>) symbol not recognised in debug command line arguments Visual Studio 2017调试命令行参数 Visual Studio 2017 中无法识别大于 (>) 符号
【发布时间】:2019-07-19 01:04:42
【问题描述】:

我目前正在尝试调试应用程序,并且在启动应用程序时我正在通过 Visual Studio 传递调试命令行参数,因为这是我调试它的唯一方法。

当我在命令行参数中使用>< 符号时,它们会被忽略。但是,通过命令提示符调用应用程序时不会发生这种情况。

我尝试过使用“&”> ,但这不起作用。谁能给点建议?

编辑:我使用的代码是

Processor.CommandLineArgs = My.Application.CommandLineArgs

使用它的一个例子是我传递"/output.txt />3"

My.Application.CommandLineArgs 有 2 个项目,"/output.txt""/3"

【问题讨论】:

  • 您能否edit 提出问题并给出您想要传递的命令或参数的实际示例,并解释您这样做的目的是什么?
  • 您能否从您的 main 方法中发布代码,因为它运行良好。我刚刚尝试将这个< = asd 放入命令行参数中,我收到了一个由 3 个组成的数组,它们分别是 <=asd
  • @Franck 我使用的代码是
    Processor.CommandLineArgs = My.Application.CommandLineArgs
    使用它的一个例子是我传递“/output.txt /> 3"
    My.Application.CommandLineArgs 有 2 项,“/output.txt”和“/3”
  • @Matt 在你的问题中格式化它。不在评论中
  • 求助。搞砸了这种格式。

标签: c# visual-studio-2017 command-line-arguments


【解决方案1】:

如果您的应用程序是控制台应用程序,只需存储您直接从Program.cs Main(string[] args) 方法接收到的值。它将包含您需要的一切。

如果您使用的是winform 项目,您可以简单地编辑同一个文件并从那里读取参数。这里是一个全新的winform project修改program.cs的简单示例

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args) // just added the args here
    {
        var myParams = args; // read the values and do something. This conserve special characters

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

【讨论】:

  • 虽然这可行,但我无法实现。该代码正在企业范围内使用,我无法更改主函数的结构(当前未传递参数数组)。
  • @Matt 是的,您可以实现,添加在入口点传递读取参数的额外功能需要几个字符。您可以执行一个简单的 if 语句并检查 args 长度是否为零,然后照常调用它。否则表示参数已通过。
  • 我的意思是我无法实现,因为这是我不允许更改的代码。这不是个人代码,而是来自我的雇主。我无法更改它。
  • @Matt 这是捕获传递给任何项目的真实参数的唯一方法。 Jeroen 提到的唯一其他解决方案是停止使用这些输出字符,因为没有其他可能的方法来捕获它们。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 2021-07-27
相关资源
最近更新 更多