【发布时间】:2019-01-23 19:45:56
【问题描述】:
为什么以管理员身份运行时这不起作用?
import subprocess
command = "wbadmin get versions"
output = subprocess.check_output(["powershell", command], timeout=120)
print(output)
当我从 powershell 或 cmd 运行它时,它可以工作。
当我使用 Popen 和communicate() 时出现错误:
"wbadmin" is not a known name, function or script..."
The original message is in german:
b''
b'wbadmin : Die Benennung "wbadmin" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines \r\nausf\x81hrbaren Programms erkannt. \x9aberpr\x81fen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern \r\nenthalten), und wiederholen Sie den Vorgang.\r\nIn Zeile:1 Zeichen:1\r\n+ wbadmin get versions\r\n+ ~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (wbadmin:String) [], CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n'
【问题讨论】:
-
您是否以管理员身份启动 Python(或您的脚本)?
-
据我所知,是的。我首先以管理员身份运行 CMD,然后运行 python。
-
在cmd中运行命令(
powershell wbadmin get versions)会输出什么?同时使用 Popen 和 communicate,并将输出粘贴到问题中。 -
"wbadmin 1.0 - Sicherungs-Befehlszeilentool (C) 版权所有 2013 Microsoft Corporation。Alle Rechte vorbehalten。FEHLER - Es wurde keine Sicherung gefunden。"当我在带有备份的服务器上运行它时,它会返回有关上次备份的信息
-
不幸的是我也没有备份,所以我无法测试它。在有备份的服务器上,如果你从 Python 运行它,你会得到什么(仍然使用 Popen 和 communicate)?
标签: python winapi subprocess