1

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

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
4

1 回答 1

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()
于 2013-04-23T15:33:01.260 回答