从 python 脚本调用 hive -e
calling hive -e from a python script
我想从我的 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)
会起作用的。也许需要对调用堆栈进行一些重构以接受列表而不是字符串。
如果您使用的是 python2.7,那么下面的代码片段将起作用。
import subprocess
command = [""" hive -e "msck repair table dashboard_report" """]
print subprocess.check_output(command,shell=True)
我想从我的 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)
会起作用的。也许需要对调用堆栈进行一些重构以接受列表而不是字符串。
如果您使用的是 python2.7,那么下面的代码片段将起作用。
import subprocess
command = [""" hive -e "msck repair table dashboard_report" """]
print subprocess.check_output(command,shell=True)