下面是我正在运行的调用sqoop的python代码,但是除了下面几行之外,它没有捕获日志
警告:/usr/hdp/2.6.4.0-91/acumulo不存在!accumulo进口将失败。请将$accumulo\u home设置为accumulo安装的根目录。
import subprocess
job = "sqoop-import --direct --connect 'jdbc:sqlserver://host' --username myuser --password-file /user/ivr_sqoop --table data_app_det --delete-target-dir --verbose --split-by attribute_name_id --where \"db_process_time BETWEEN ('2018-07-15') and ('9999-12-31')\""
print job
with open('save.txt','w') as fp:
proc = subprocess.Popen(job, stdout=fp, stderr=subprocess.PIPE, shell=True)
stdout, stderr = proc.communicate()
print "Here is the return code :: " + str(proc.returncode)
print stdout`
如果我打电话的方式有问题,请告诉我。
注意:单个sqoop cmd运行良好并生成所有日志。
我也试过下面的方法,结果是一样的
import subprocess
job = "sqoop-import --direct --connect 'jdbc:sqlserver://host' --username myuser --password-file /user/ivr_sqoop --table data_app_det --delete-target-dir --verbose --split-by attribute_name_id --where \"db_process_time BETWEEN ('2018-07-15') and ('9999-12-31')\""
proc = subprocess.Popen(job, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
stdout, stderr = proc.communicate()
并在cmd的末尾使用'2>mylog.log'
import subprocess
job = "sqoop-import --direct --connect 'jdbc:sqlserver://host' --username myuser --password-file /user/ivr_sqoop --table data_app_det --delete-target-dir --verbose --split-by attribute_name_id --where \"db_process_time BETWEEN ('2018-07-15') and ('9999-12-31')\" > mylog.log "
proc = subprocess.Popen(job, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = proc.communicate()
我发现了下面类似的问题,但也没有答案。
子进程popen:忽略accumulo警告并继续执行sqoop
1条答案
按热度按时间bxfogqkk1#
既然你添加了
shell=True
,它没有捕获sqoop日志。请删除shell=True
从你的命令中添加universal_newlines=True
,它将显示控制台日志。工作代码: