C
C#4mo ago
Turwaith

Very weird params passing error to main Method

I have a tool to which I pass arguments via the command line. It is three arguments, the first one is a name, the second and third ones are paths. Now these paths can be such with spaces in them. So I pass them using double-quotes. Let's say I pass the following: .\myprogram.exe SomeName "C:\Projects\My Project\src" "C:\Projects\My Project\src\bin\x64\SomeProgram.exe" Now I would expect to receive
args[0] == SomeName
args[1] == C:\Projects\My Project\src
args[2] == C:\Projects\My Project\src\bin\x64\SomeProgram.exe
args[0] == SomeName
args[1] == C:\Projects\My Project\src
args[2] == C:\Projects\My Project\src\bin\x64\SomeProgram.exe
But what I get instead is
args[0] == SomeName
args[1] == C:\Projects\My Project\src" C:\Projects\My
args[2] == Project\src\bin\x64\SomeProgram.exe
args[0] == SomeName
args[1] == C:\Projects\My Project\src" C:\Projects\My
args[2] == Project\src\bin\x64\SomeProgram.exe
So the third argument does not get recognized correctly and is split at the space for some reason. I have tried everything. Using double quotes for all three arguments, using no quotes at all, escaping all possible characters... I just don't understand that behaviour.
4 Replies
Angius
Angius4mo ago
Works on my machine
No description
Angius
Angius4mo ago
What's the actual code that gives you this weird result?
Omnissiah
Omnissiah4mo ago
are you starting the tool from cmd or what
Turwaith
TurwaithOP4mo ago
Basically the same, for debugging reasons I have added a console.WriteLine for all three args. I have also tried opening the code and putting a breakpoint right at the beginning of the main method so I can explore the args array. Which shows me the same results. And it not only happens when I start the program from command line but also when I start it in Rider using the launchSettings.json file to pass the arguments. Same issue Dammit. I found the issue. The second parameter actually had a \ at the end. Which was interpreted as an escape character for the closing " of the second argument Sometimes you just have to write it down to find it yourself. Thanks for rubberducking guys
Want results from more Discord servers?
Add your server