-1

我正在使用 python 子进程执行 isql 命令。我正在使用下面的代码来捕获输出和错误消息。

command = "./isql -S "+mdbserver+" -U "+muserid+" -P "+mpassword+" -D "+mdatabase+" -s '"+self.Delimiter+"' -w 99999 <<EOF\nSET NOCOUNT ON\n"+Query+"\ngo\nEOF"
output, err = subprocess.Popen(command,stdout=subprocess.PIPE,shell=True,cwd=sybase_bin)

我的 isql 命令的输出和错误出现在输出变量中。如何在 err 变量中捕获 isql 的错误消息。

4

1 回答 1

1

使用stderr参数:

proc = subprocess.Popen(
    command,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    shell=True,
    cwd=sybase_bin
)

然后:

output, error = proc.communicate()

有关更多详细信息,请参阅文档

于 2015-10-26T10:37:07.467 回答