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