这是脚本片段:
import subprocess
output = subprocess.run(["psexec.exe",
"\\\\<machine-name>",
"/u", "<machine-name>\\TestAdmin",
"/p", "<password>",
"cmd /c dir"],
capture_output=True,
text=True,
shell=True)
print(output.stdout)
print(output.stderr)
这是我得到的输出:
E:\python-scripts>python runpsexec.py
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
The system cannot find the path specified.
Connecting to <machine-name>...
Starting PSEXESVC service on <machine-name>...
Connecting with PsExec service on <machine-name>...
Starting cmd /c dir on <machine-name>...
PsExec could not start cmd /c dir on <machine-name>:
我还尝试传递-s
选项以将其作为系统帐户运行。如果我直接从cmd提示符下运行psexec,则可以运行相同的命令并获得正确的输出。
通过psexec
运行subprocess.run()
有什么限制吗?还是我错过了什么?