Could not get command line arguments correctly in C #

In C # .Net, I cannot get the command line argument correctly. This has problems in case I give a command like:

myProgram.exe "c:\inputfolder\" "d:\output.txt"

due to the backslash character (which I think acts like an escape character) in the args [] array, I get only one argument instead of two. It works fine if I gave it without a backslash:

myProgram.exe "c:\inputfolder" "d:\output.txt"

or without double quotes:

myProgram.exe c:\inputfolder\ "d:\output.txt"
+3
source share
4 answers

I have never encountered such a problem, but if you like to analyze the command line yourself, use System.Environment.CommandLine to get it.

+5
source

, , .

+4

. :

myProgram.exe "c:\inputfolder\\" "d:\output.txt"

:

using System;

class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i < args.Length; i++)
        {
            Console.WriteLine(string.Format("Argument {0}: {1}", i, args[i]));
        }
    }
}
+4

Source: https://habr.com/ru/post/1707175/


All Articles