C# - passing arguments with space in between them to a process
I'm trying to pass an argument to a process a folder with space in its开发者_JAVA百科 name. It doesn't recognize the folder. How can i do that?
string my_arg = @"C:\\program files\\my folder with spaces";
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = @"C:\batches\my_batch.bat";
proc.Arguments = @my_arg ;
Process.Start(proc);
the process wont start - it does work if i use a folder with no spaces in the name. Thank you!
You’re using literal strings; there is no need to escape the backslashes, and indeed if you do then there’s no need to use a literal string in the first place.
The spaces on the other hand require special care – encase the argument into quotes solves this.
string my_arg = @"""C:\program files\my folder with spaces""";
try this:
string my_arg = "\"C:\\program files\\my folder with spaces\"";
Try doing the following as foldernames with spaces should be quoted in cmd:
string my_arg = @"""C:\\program files\\my folder with spaces""";
Please Try this
string my_arg = @"\"C:\program files\my folder with spaces\|";
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = @"C:\batches\my_batch.bat";
proc.Arguments = @my_arg ;
Process.Start(proc);
精彩评论