Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How ProcessStartInfo.Argument consider arguments

Tags:

c#

process

I am using following code to start another process with argument, here i pass a string path as argument, path returned as c:\documents and settings\\local settings: :

string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)).FullName(); //path = c:\documents and settings\<username>\local settings

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = path;
Process.Start(startInfo);

I would like to pass the path as one argument, a whole string. But I found out the path has been separated by multiple arguments, it actually separated by every space. In this case, it pass c:\documents as first argument, and as second argument and settings\\local as third argument...

I want to pass them as one argument rather than 4 arguments. How can do that with StartInfo.Argument?

like image 674
Chelseajcole Avatar asked Mar 12 '13 15:03

Chelseajcole


3 Answers

I am not sure, if it works, but try to use " around your path:

startInfo.Arguments = "\"" + path + "\"";

This will wrap your string in " and so, whitespaces will be ignored.

like image 149
bash.d Avatar answered Oct 20 '22 02:10

bash.d


The Process object treats arguments in exactly the same way as the Console. Wrap any arguments containing spaces with double quotes: "\"c:\documents and settings\local settings\"".

A good tip is to try to run the process from the console with whatever arguments you've supplied. This makes it easier to understand error feedback than running from a Process object.

like image 5
pixelbadger Avatar answered Oct 20 '22 00:10

pixelbadger


Wrap your argument in quotation marks:

startInfo.Arguments = "\"" + path + "\"";
like image 4
Rotem Avatar answered Oct 20 '22 00:10

Rotem