开发者

Process.Start Argument Problem --- Escaping an "=" character?

开发者 https://www.devze.com 2022-12-19 02:33 出处:网络
I\'ve been using System.Diagnostics.Process.Start().For example: string target = @\"c:\\te=mp\\test\";

I've been using System.Diagnostics.Process.Start(). For example:

string target = @"c:\te=mp\test";
System.Diagnostics.Process.Start("explorer.exe", target)

The target variable is actually supplied more dynamically and does on occasion include an "=" sign which is a legal character in filenames and directories.

The issue is that this triggers an error indicating, "The Path 'mp\test' does not exist or is not a directory." 开发者_开发百科It seems that the path argument is cutoff to the left of the "=" character.

Is there a way to escape the "=" characteror otherwise work-around this issue?


try wrapping it in quotes, e.g.

string target = @"""c:\te=mp\test""";


Put quotes around the offending parameter. For example:

System.Diagnostics.Process.Start("explorer.exe", "\"" + target + "\"");


Just use double quotes:

System.Diagnostics.Process.Start("explorer.exe",  @"""c:\te=mp\test""");
0

精彩评论

暂无评论...
验证码 换一张
取 消