Skip to main content
 首页 » 编程设计

python之从 python 脚本调用 hive -e

2024年10月25日23jiqing9006

我想从我的 python 脚本中运行一个非常简单的配置单元命令。我正在尝试使用 hive -e,但出现错误

def hive(): 
    cmd = "hive -e \"msck repair table dashboard_report\"" 
    print(cmd) 
    check_call(cmd) 

这是我遇到的错误

hive -e "msck repair table dashboard_report" 
Traceback (most recent call last): 
File "/home/yosi/work/source/slg/tiger/src/main/resources/python/tiger.py", line 59, in <module> 
hive() 
File  "/home/yosi/work/source/slg/tiger/src/main/resources/python/tiger.py", line 57, in hive 
check_call(cmd) 
File "/usr/lib/python2.7/subprocess.py", line 535, in check_call 
retcode = call(*popenargs, **kwargs) 
File "/usr/lib/python2.7/subprocess.py", line 522, in call 
return Popen(*popenargs, **kwargs).wait() 
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ 
errread, errwrite) 
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child 
raise child_exception 
OSError: [Errno 2] No such file or directory 

请您参考如下方法:

您的 check_call 函数正在调用 subprocess.Popen。如果您想将参数传递给该函数,则必须将它们传递到列表中。

可能:

cmd = ["hive", "-e", "\"msck repair table dashboard_report\""] 
check_call(cmd) 

会起作用。也许需要对调用堆栈进行一些重构以接受列表而不是字符串。