windows 如何在windows命令行中转义参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2403647/
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-09 07:09:52  来源:igfitidea点击:

How to escape parameter in windows command line?

windowscommand-lineescaping

提问by Sergiy Belozorov

I need to run the following command from the command line in Windows 7:

我需要从 Windows 7 的命令行运行以下命令:

SumatraPDF.exe -inverse-search "\"C:\Program Files\eclipse\inverse_search.bat\" \"%f\" %l"

SumatraPDF.exe -inverse-search "\"C:\Program Files\eclipse\inverse_search.bat\" \"%f\" %l"

However I need to modify it a little, since my installation of Eclipse is located in here:

但是我需要稍微修改一下,因为我的 Eclipse 安装位于:

C:\Program Files (x86)\Eclipse (C++)

C:\Program Files (x86)\Eclipse (C++)

How do I escape this line correctly? Do I need to escape parenthesis and pluses too? Or is it just enough to escape double quotes?

如何正确转义这条线?我也需要转义括号和加号吗?或者它是否足以逃避双引号?

回答by Esteban Küber

SumatraPDF.exe -inverse-search "\"C:\Program Files (x86)\Eclipse (C++)\inverse_search.bat\" \"%f\" %l"

回答by Sniggerfardimungus

When in doubt, escape everything. I find that I don't need to escape (), %, or +, though.

当有疑问时,逃避一切。不过,我发现我不需要转义 ()、% 或 +。

回答by Luke

I don't even think you need to escape the quotes; it should be enough to do:

我什至认为你不需要逃避引号;这样做应该足够了:

SumatraPDF.exe -inverse-search ""C:\Program Files (x86)\Eclipse (C++)\inverse_search.bat" %f %l"