首页 > 解决方案 > 使用python从直线记录计数

问题描述

我正在尝试使用 python 从直线获取记录计数,我收到错误 PermissionError: [Errno 13] Permission denied: "beeline -u ${beecon} -e 'select count(*) from dbname.tableName where signInDate = 20210315 '; $ {beecon} 是Linux中的全局变量,它指的是连接细节。如果我直接在Linux中使用它,如下命令,我得到正确的记录计数

beeline -u ${beecon} -e 'select count(*) from dbname.tableName where signInDate = 20210315';

我希望使用 Python 获得相同的输出,我的代码:

import os
import subprocess

command = "beeline -u ${beecon} -e 'select count(*) from dbname.tableName where signInDate = 20210315';"

countresult = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
countresult.wait()
s_output, S_err = countresult.communicate()
s_return = countresult.returncode

我正在寻找最少的代码和最少的库。谢谢

标签: python-3.xbeeline

解决方案


推荐阅读