I have a console project which I want to start with some parameters argc
. I want to pass to it a path from my computer, let's say C:\\My Folder
. How can I pass the spaces?
When I try to read it I obtain something like C:\\My
. I've read that I can pass them by using "
. If so, how can I pass those to a string ("C:\My Folder"
) because I am start this program by using the Process.Start
and ProcessStartInfo
commands?
If you want to pass named string arguments containing spaces in between to the python script, you can simply put the text in double quotes.
How do you pass a command line argument with spaces? By enclosing the path (or parts of it) in double quotation marks ( ” ). By adding a caret character ( ^ ) before each space. (This only works in Command Prompt/CMD, and it doesn't seem to work with every command.)
Simply enclose the space character between two double-quotes to pass it to your app's main method.
Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name. Inside the script, the $1 variable references the first argument in the command line, $2 the second argument and so forth. The variable $0 references to the current script.
Wrap the argument in double quotes:
"c:\My Folder\some.exe" /a="this is an argument"
As a string passed to Process.Start:
process.StartInfo.Aguments = "\"this is an argument\"";
Check out this post & answer for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With