C# Cmd 进程无法使用空格
我从我的应用程序中打开 cmd.exe 并将其导航到一个文件,但问题是如果文件路径中有空格,它就不会去那里。
Process.Start("cmd.exe", "/C choice /C Y /N /D Y /T 3 & cd C:\Temp Folder");
我猜它只会查找临时文件夹,而不是查找临时文件夹。
一种方法是用“”包裹路径,但我不能用字符串来完成。 (尝试过“”)
另一种方法是循环路径,找到空格并用某些东西替换它们,但我不知道用什么替换。
我可以通过这两种方式获得一些帮助(如果你有更好的方式,那就太好了)
I am opening cmd.exe from my application and navigating it to a file but the problem is that if the file path has spaces in it, it won't go there.
Process.Start("cmd.exe", "/C choice /C Y /N /D Y /T 3 & cd C:\Temp Folder");
Instead for looking of Temp Folder, it will only look for temp I guess.
One way is to wrap the path with " " but I can't do it in a string. (tried ' ')
Another way is to loop through the path, find spaces and replace them with something, but I don't know with what.
I could use some help with either of this ways (if you have a better one, that's great)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字符串中的
\
需要转义,并且需要在双引号中包含带有空格的文件夹名称。尝试
或
The
\
in the string needs to be escaped and you need to include folder names with space in double quotes.Try
or
您需要对特殊字符使用转义字符
\
。因此,要转义 " ,请使用\"
You need to use an escape character
\
for special characters. So, to escape the " , use\"