从PYTHON中的SQLCMD获取错误消息

时间:2013-04-23 14:55:32

标签: python subprocess sqlcmd

我真的很亲近。这给出了查询的输出,但我只需要检索错误消息。我觉得有一点调整就可以了......

import subprocess

command_process = subprocess.Popen(
    ['sqlcmd', '-E', '-V1', '-S', '1070854A\AISP', '-i', 'NewStructures.sql'],
    shell=True,
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
)
command_output = command_process.communicate()[0]

print command_output

1 个答案:

答案 0 :(得分:0)

这样的事情?

import subprocess

command_process = subprocess.Popen(
    ['sqlcmd', '-E', '-V1', '-S', '1070854A\AISP', '-i', 'NewStructures.sql'],
    shell=True,
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
)
command_output = command_process.communicate()[0]

print command_process.stderr.read()