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