使用子进程 hdfs "cat: Illegal file pattern: Illegal character range near index 11"打开 Python HDFS 文件

标签 python hadoop hdfs cat

我正在尝试加载存储在 HDFS 中的 Hadoop 集群上的 informatica 日志文件。我在 Python 中使用 subprocess 来执行此操作,但相信由于文件名而出现错误,我不确定如何解决它。

我得到的错误是“cat:非法文件模式:索引 11 附近的非法字符范围”

我的代码是:

input = subprocess.Popen(["hadoop", "fs", "-cat", '/corp_staffs/IT/IICOE/process/infa_stats/WorkflowLogs/infra.[08-04-2015-(15_19)].1438719569664.log'], stdout=subprocess.PIPE)

# read the lines into an array
for line in input.stdout:
        print line

我可以重命名每个文件以避免 cat 认为文件名中有正则表达式,但我宁愿不这样做。有没有办法解决这个问题?

最佳答案

quotechars=re.compile('|'.join(re.escape(s) for s in r'\[]()*?'))
def quote_name(filename):
    return re.sub(quotechars, r'\\\g<0>', filename)

input = subprocess.Popen(
    [
        "hadoop", "fs", "-cat",
        quote_name('/corp_staffs/IT/IICOE/process/infa_stats/WorkflowLogs/infra.[08-04-2015-(15_19)].1438719569664.log')
    ], stdout=subprocess.PIPE)

关于使用子进程 hdfs "cat: Illegal file pattern: Illegal character range near index 11"打开 Python HDFS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32055025/

相关文章:

android - 如何实现一个Android应用程序来连接服务器

xml - 将 XML 文件加载到 Hive 表

Hadoop/Yarn 分布式 shell 示例

hadoop - 为什么在此Hadoop 1.2.1安装中无法启动NameNode?

hadoop - 具有相同 kerberos 领域的两个集群

python-3.x - df.coalesce(1) 是什么意思?

python - 忽略 SublimeLinter3(flake8 插件)中的特定警告

python - 在 Pandas 中,如何计算给定另一列值的列值的相对概率?

python - Pyparsing 在上下文中运行

python - 为什么这个 CountVectorizer 输出与我的字数统计不同?