apache commons-cli如何解析\\t字符

how does apache commons-cli parses \\t character

我需要在 commons-cli 中将制表符作为参数传递。当我将参数作为“\\t”给出时,命令行解析器将其解析为“\t”字符本身而不是 TAB () white space。我怎样才能做到这一点?

编辑:

按照@centic 的建议,更新了我如何调用应用程序的问题。我在 Unix 中使用命令行调用,其中反斜杠被检测为转义字符。

更准确地说,我在提交 hadoop 流作业时使用它,如果这有帮助的话。例如:

hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.4.0.jar -D stream.map.output.field.separator="\t" -file mapper.py -mapper mapper.py -file reducer.py-reducerreducer.py-输入/输入-输出/输出

A​​pache Hadoop 使用 Apache Commons-cli 作为命令行实用程序。所以我假设“\\t”解析为“\t”并作为选项传递。但是当我通过调试 hadoop 源代码打印它时,它本身打印为“\t”(字符串文字)而不是 TAB 白色 space 字符。

当您在 shell 中调用应用程序时试图提供此信息,这实际上与 shell 如何处理此类特殊字符有关,而不是 commons-cli 或 Java.

手册中的 shell (which is the default shell on most unix/linux versions nowadays) has the special syntax $'\t' for this, see this section

所以你的电话应该是这样的

HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.4.0.jar -D 
stream.map.output.field.separator=$'\t' -file mapper.py -mapper 
mapper.py -file reducer.py -reducer reducer.py -input /in -output /out