在Windows cmd中以带百分号的引号传递参数

在Windows cmd中以带百分号的引号传递参数,windows,hadoop,cmd,escaping,stat,Windows,Hadoop,Cmd,Escaping,Stat,我正在尝试使用Hadoop的命令从我的HDFS中检索文件信息。在Linux上,您可以将格式化字符串传递给stat(类似于GNUstatbuiltin),如下所示: 但我不知道如何在Windows的cmdprompt中实现这一点: C:\> hdfs dfs -stat "type:%F" /file C:\> hdfs dfs -stat "type:%F" / -stat: java.net.URISyntaxException: Relative path in absolut

我正在尝试使用Hadoop的命令从我的HDFS中检索文件信息。在Linux上,您可以将格式化字符串传递给
stat
(类似于GNU
stat
builtin),如下所示:

但我不知道如何在Windows的
cmd
prompt中实现这一点:

C:\> hdfs dfs -stat "type:%F" /file

C:\> hdfs dfs -stat "type:%F" /
-stat: java.net.URISyntaxException: Relative path in absolute URI: type:F
...
…它似乎试图将第一个参数解释为路径,而不是第二个参数。所以我想“也许我需要包含文字引号?”尝试用
^“
转义引号是行不通的:

C:\> hdfs dfs -stat "^"type:%F^"" /
-stat: java.net.URISyntaxException: Relative path in absolute URI: ^^type:F
...
C:\> hdfs dfs -stat '^"type:%F^"' /
-stat: java.net.URISyntaxException: Relative path in absolute URI: 'type:F'
...
C:\> hdfs dfs -stat '^^"type:%F^^"' /
-stat: java.net.URISyntaxException: Relative path in absolute URI: 'type:F%5E%5E'
...
…事实上,它看起来像是自动转义了我发送的
^
,但根本没有发送任何引号。尝试用单引号而不是双引号括住整个参数也不起作用:

C:\> hdfs dfs -stat "^"type:%F^"" /
-stat: java.net.URISyntaxException: Relative path in absolute URI: ^^type:F
...
C:\> hdfs dfs -stat '^"type:%F^"' /
-stat: java.net.URISyntaxException: Relative path in absolute URI: 'type:F'
...
C:\> hdfs dfs -stat '^^"type:%F^^"' /
-stat: java.net.URISyntaxException: Relative path in absolute URI: 'type:F%5E%5E'
...
这一次,它包含了单引号,但再次跳过了双引号。双转义克拉也不起作用:

C:\> hdfs dfs -stat "^"type:%F^"" /
-stat: java.net.URISyntaxException: Relative path in absolute URI: ^^type:F
...
C:\> hdfs dfs -stat '^"type:%F^"' /
-stat: java.net.URISyntaxException: Relative path in absolute URI: 'type:F'
...
C:\> hdfs dfs -stat '^^"type:%F^^"' /
-stat: java.net.URISyntaxException: Relative path in absolute URI: 'type:F%5E%5E'
...
三倍逃离克拉产生的结果与使用一克拉相同

我发现一个笨拙的解决方案是用
%3
开头格式化字符串,而不是用引号括起来

C:\> hdfs dfs -stat %3%u /
3Andrew.Watsonuu

C:\> hdfs dfs -stat %3%u%g /
3Andrew.Watsonsupergroupgg
…但是您可以看到,返回的字符串在开始处有一个
3
,最后一个标志字符在结尾处加倍
uu
gg
。我认为这是因为
%N
被转换为我传递给该函数的参数,如:

C:\> hdfs dfs -stat %0 /
stat: `hadoop': No such file or directory
2019-09-25 12:28:00

C:\> hdfs dfs -stat %1 /
stat: `fs': No such file or directory
2019-09-25 12:28:00

C:\> hdfs dfs -stat "%2" /
-stat: Illegal option -stat
您可以看到,
%0
%1
%2
对应于该命令中的第一个、第二个和第三个标记。因此,当我调用%3时,它会将第四个参数替换为自身。这解释了奇怪的重复、错误的输出:

C:\> hdfs dfs -stat %3"repeat" /
3repeat"repeat"repeat
因此,到目前为止,我提出的最佳解决方案是在末尾传递一个多余的参数(这将引发错误),然后在命令的前面引用该参数,如:

C:\> hdfs dfs -stat -R %6 / "%%u %%g %%Y" 2> nul
Andrew.Watson supergroup 1569414480510
Andrew.Watson supergroup 1568728730673
...
Andrew.Watson supergroup 1568103636381
Andrew.Watson supergroup 1568103590659
它在最后抛出那个错误,我通过管道将它隐藏到
nul
。一定有更好的方法来做到这一点。有什么想法吗