如何 "apt full-upgrade" 使用 python 脚本

How to "apt full-upgrade" using a python script

我希望能够 1) 通过 python 升级我的 RPi 和 2) 捕获结果(作为字符串)以查看进展情况。我怎样才能自动传递任何相关的 -Y 响应。

我最终使用了:

command = ['apt', 'full-upgrade', '-y']
result = str(subprocess.run(command, capture_output=True).stdout, 'ascii')

试试这个

import subprocess
cmd = "sudo apt full-upgrade -y"
result = subprocess.Popen(cmd, shell=True)