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
?
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.
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.
Wrap your argument in quotation marks:
startInfo.Arguments = "\"" + path + "\"";
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