这篇文章上次修改于 607 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
语法:
subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)
执行cmd命令并返回结果到字符串。
用法:
import subprocess
output = check_output(["cat", "/etc/hostname"]).strip()
print(output)
以上脚本会执行 cat /etc/hostname
命令然后将结果赋值给 output
变量。strip()
可以将 string 的前后空格去掉。
没有评论