Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a string with spaces in it as start arguments for a program

Tags:

c#

process

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?

like image 517
Simon Avatar asked Jun 18 '12 14:06

Simon


People also ask

How do you pass a string with spaces?

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 can you send an argument to a program that includes a space or spaces?

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.)

How do you pass a space in a string in Java?

Simply enclose the space character between two double-quotes to pass it to your app's main method.

How do you pass arguments with spaces to a shell script?

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.


1 Answers

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.

like image 102
bluevector Avatar answered Oct 14 '22 01:10

bluevector