© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
6 replies
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"
.\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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Passing back to the main thread
C#CC# / help
13mo ago
unable to call main method
C#CC# / help
3y ago
❔ ✅ How to store a method's variable to main method?
C#CC# / help
3y ago