vb.net 路径中有空格的 CMD 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15234758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:38:11  来源:igfitidea点击:

CMD command with space in path

c#vb.netcmd

提问by B3st0fth3w0rst

I am having an issue with the spaces in my command. I am trying to run the cmd prompt and execute a program that takes command line arguments. I need the cmd window to remain open after the process is finished executing.

我的命令中的空格有问题。我正在尝试运行 cmd 提示符并执行一个接受命令行参数的程序。进程执行完毕后,我需要 cmd 窗口保持打开状态。

I managed to get it working in another section of code, but this time i am almost sure it has to do with the spaces in the path of the argument. If i use a path with no spaces, it works fine. I tried to escape the quotes, but either i am doing it incorrectly, or escaping the quotes do not work.

我设法让它在另一段代码中工作,但这次我几乎可以肯定它与参数路径中的空格有关。如果我使用没有空格的路径,它工作正常。我试图转义引号,但要么我做错了,要么转义引号不起作用。

Basically, I need to make the line below work with spaces and keep the cmd window open after the execution...

基本上,我需要使下面的行与空格一起使用并在执行后保持 cmd 窗口打开...

 Dim ps As Process = System.Diagnostics.Process.Start("cmd /k", "C:\common\tools\tap.exe -f flash C:\Users\test project\Desktop\image.signed")

I'm know the space between "test" and "project" is the issue, but i haven't been able to get around it.

我知道“测试”和“项目”之间的空间是问题所在,但我无法绕过它。

Thanks in advance for your help.

在此先感谢您的帮助。

回答by LittleBobbyTables - Au Revtheitroad

Wrap the path in double-quotes, like this:

将路径用双引号括起来,如下所示:

"C:\common\tools\tap.exe -f flash ""C:\Users\test project\Desktop\image.signed"""

Giving you:

给你:

Dim ps As Process = System.Diagnostics.Process.Start ("cmd /k", "C:\common\tools\tap.exe -f flash ""C:\Users\test project\Desktop\image.signed""")