我正在尝试加载informatica日志文件,这些日志文件存储在HDFS中的Hadoop集群中。我正在使用Python中的子进程来完成这个任务,但是我相信,由于文件名的原因,我得到了一个错误,并且我不知道如何解决这个问题。
我得到的错误是"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我可以重命名每个文件,以避免猫认为文件名中有正则表达式,但我宁愿不这样做。有办法解决这个问题吗?
发布于 2015-08-17 16:28:30
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)https://stackoverflow.com/questions/32055025
复制相似问题