我已经编写了一个python代码来检查文件是否存在于hadoop文件系统中。python函数接收从另一个函数传递的位置,并在检查中检查bash代码是否存在该位置。
def check_file_exists_in_hadoop(loc):
yourdir = "/somedirectory/inhadoop/"+loc
cmd = '''
hadoop fs -test -d ${yourdir};
if [ $? -eq 0 ]
then
echo "Directory exists!"
else
echo "Directory does not exists!"
fi
'''
res = subprocess.check_output(cmd, shell=True)
output = (str(res, "utf-8").strip())
print(output)
if output == "Directory exists!":
print("Yay!!!!")
else:
print("Oh no!!!!")
如何在代码的bash部分中传递“yourdir”变量。