程序 A(cmd.exe\C)(接受 1 个参数)
程序 B:(接受 1 个或多个参数)
C1,C2,C3, ... : 一个 agruments 列表
如果我在 cmd 提示符下输入 A B C1 C2 C3
,
期望的解释是
A (B (C1 C2 C3))
(C 是 B 的参数,B 是 A 的参数)
但不是 A (B) (C1) (C2) (C3)
(B,C1,C2, C3, .... 是 A 的参数)
我应该如何在 cmd 提示符下转义/重定向/管道?
提前致谢
最佳答案
根据 Microsoft's documentation ,您可以对管道使用 |
运算符。
您需要将命令重写为:
B C1 C2 C3 | A
希望这对您有所帮助。
更新
自从你更新了你的问题,我猜你正在尝试做类似的事情:
cmd.exe /C B C1 C2 C3
你可以用 ^
转义特殊字符
或者尝试像这样引用字符串:
cmd.exe /C "B C1 C2 C3"
更新 2
如果您在使用 cmd.exe/C
和引号(例如 B、C1、C2、C3 包含空格)时遇到问题,您应该用另一对引号将整个命令括起来
cmd.exe /C ""B" "C1" "C2" "C3""
仅供引用,在 Microsoft's documentation on cmd.exe 的 Processing quotation marks
部分:
If you specify /c or /k, cmd processes the remainder of string and quotation marks are preserved only if all of the following conditions are met:
- You do not use /s.
- You use exactly one set of quotation marks.
- You do not use any special characters within the quotation marks (for example: &<>( ) @ ^ |).
- You use one or more white-space characters within the quotation marks.
- The string within quotation marks is the name of an executable file.
If the previous conditions are not met, string is processed by examining the first character to verify whether or not it is an opening quotation mark. If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. Any text following the closing quotation marks is preserved.
您可能想阅读 Syntax : Escape Characters, Delimiters and Quotes也是:
To launch a batch script with spaces in the Program Path requiring "quotes"
CMD /k ""c:\batch files\test.cmd" "Parameter 1 with space" "Parameter2 with space""
关于windows - 如何在cmd中调用嵌套程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598916/