【发布时间】:2016-10-28 04:33:39
【问题描述】:
我在 PowerShell 控制台会话中,尝试从 PowerShell 命令行运行存在于 cwd 中的 Gradle 脚本。
Gradle 命令接受一个参数,该参数包括可以包含一个或多个管道字符的引号,我一生都无法弄清楚如何让 PowerShell 仅使用一行(或任意数量的行)来转义它,实际上 - 但我对多线解决方案不感兴趣)。
命令如下:
./gradlew theTask -PmyProperty="thisThing|thatThing|theOtherThing"
...产生此错误:
'thatThing' is not recognized as an internal or external command, operable program or batch file.
我已经尝试了所有这些变体,但都不起作用。有什么想法吗?
./gradlew theTask -PmyProperty="thisThing`|thatThing`|theOtherThing"
./gradlew theTask -PmyProperty=@"thisThing|thatThing|theOtherThing"
./gradlew theTask -PmyProperty="thisThing\|thatThing\|theOtherThing"
./gradlew theTask -PmyProperty="thisThing\\|thatThing\\|theOtherThing"
./gradlew theTask -PmyProperty="thisThing^|thatThing^|theOtherThing"
【问题讨论】:
-
你试过
^|吗? -
@Jean-FrançoisFabre:是的。我会把它添加到列表中。我认为这是一个 DOS shell 转义字符
-
对不起,那是猜测。然而,我已经尝试过这个 `echo theTask -PmyProperty="thisThing|thatThing|theOtherThing"`` 并且 echo 命令可以正常工作(Windows 10)。可以试试吗?
-
是的,这回显了出现在“echo”之后的参数。但是,我需要它使用相同的参数运行 cwd 中的 gradle 脚本
-
所以问题必须存在于 gradle 脚本中。您是否尝试过在脚本开头打印一些内容?
标签: shell powershell command-line escaping