使用 Paramiko 无法获得 stderr

Sha*_*n-x 0 python mysql ssh paramiko python-2.7

由于某些原因,我不得不使用mysqlParamiko。

我有这个(简化的)片段:

stdin, stdout, stderr = c.exec_command("mysql stuff -e 'rename table foo to bar'")
print stdout.read()
print stderr.read()
Run Code Online (Sandbox Code Playgroud)

但如果表foo不存在,我就没有输出(没有stdoutstdin输出)。

但这很奇怪,因为:

stdin, stdout, stderr = c.exec_command("mysql stuff -e 'rename table foo to bar'")
if stderr.read()
    print "Error: %s" % stderr.read()
    print type(stderr.read())
Run Code Online (Sandbox Code Playgroud)

有这个输出:

Error:
<type 'str'>
Run Code Online (Sandbox Code Playgroud)

mysql错误通常是:

第 1 行出现错误 1017 (HY000):找不到文件:“./stuff/foo.frm”(错误号:2 - 没有这样的文件或目录)

我想要更详细的错误输出,但我不能。为什么?

Mar*_*ryl 5

你无法阅读stdin。是输入,不是输出。

这就是为什么您会收到“文件未打开以供阅读”的原因。与你的命令无关mysql