开发者

how to make sure the file name is quoted when it has space

开发者 https://www.devze.com 2023-01-29 09:40 出处:网络
When use Process.startInfo.Arguments, I ha开发者_如何学运维ve filename as one of the argument,

When use Process.startInfo.Arguments, I ha开发者_如何学运维ve filename as one of the argument,

StartInfo.Arguments = filename

I am wondering how to make sure it is correct in the case that filename is "test test".


I would simply always quote it; since "test" is valid too.

I don't know if there is inbuilt file escaping anywhere, but

procStart.Arguments = "blah blip -in \"" + filePath + "\" more args";

should do...

If you wanted you could get fancy with checking the input string (filePath above), but it probably isn't worth checking the edge-cases. For the same reason that if I'm writing TSQL over an unknown table, I'd always add explicit [ / ] (without bothering to check if it needs it).

0

精彩评论

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