管道字符“|”这时候出乎意料
pipe character "|" was unexpected at this time
我有以下脚本可以在多个 JAR 文件中找到 class。 Class 名称作为字符串参数传递。
set ARG=%1
for /R %G in (*.jar) do @jar -tvf %G | find %ARG% > NUL && echo %G
给我以下错误
> findClassInJar.bat "ContentPartition"
> set ARG="ContentPartition"
| was unexpected at this time.
> for /R G | find "ContentPartition" > NUL && echo G
如何解决这个错误?
对于批处理文件中的循环变量,您应该使用 %%
而不是 %
。即,将 %G
替换为 %%G
。否则,它将被解释为参数。
我有以下脚本可以在多个 JAR 文件中找到 class。 Class 名称作为字符串参数传递。
set ARG=%1
for /R %G in (*.jar) do @jar -tvf %G | find %ARG% > NUL && echo %G
给我以下错误
> findClassInJar.bat "ContentPartition"
> set ARG="ContentPartition"
| was unexpected at this time.
> for /R G | find "ContentPartition" > NUL && echo G
如何解决这个错误?
对于批处理文件中的循环变量,您应该使用 %%
而不是 %
。即,将 %G
替换为 %%G
。否则,它将被解释为参数。