The command line processing should be the same, therefore something else is going on. When I try this:
class Program {
[STAThread]
static void Main(String[] args) {
Console.WriteLine("Have {0} arguments", args.Length);
for (int i = 0; i < args.Length; ++i) {
Console.WriteLine("{0}: {1}", i, args[i]);
}
}
}
and then it from the various locations I get 100% consistent results, the only way of getting arguments "merged" is to enclose them in quotes on the command line (which is specifically there to allow you do have arguments containing a space, see the last example below):
PS C:...inDebug> .ConsoleApplication1.exe one two three
Have 3 arguments
0: one
1: two
2: three
PS C:...inDebug> pushd ..
elease
PS C:...inRelease> .ConsoleApplication1.exe one two three
Have 3 arguments
0: one
1: two
2: three
PS C:...inRelease> pushd ....objdebug
PS C:...objDebug> .ConsoleApplication1.exe one two three
Have 3 arguments
0: one
1: two
2: three
PS C:...objDebug> pushd ..
elease
PS C:...objRelease> .ConsoleApplication1.exe one two three
Have 3 arguments
0: one
1: two
2: three
PS C:...objRelease> .ConsoleApplication1.exe -file test.txt
Have 2 arguments
0: -file
1: test.txt
PS C:...objRelease> .ConsoleApplication1.exe "-file test.txt"
Have 1 arguments
0: -file test.txt
Additional While launching from a command prompt makes it easy to see what is being passed it can be hard to check when another application launches yours. However tools like Process Explorer will show the command line used to start a program (double click on a process and look at the image tab).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…