更新时间:2023-02-02 20:39:13
您可以使用 subprocess
库中的 check_call
.
You can use check_call
from the subprocess
library.
from subprocess import STDOUT, check_call
import os
check_call(['apt-get', 'install', '-y', 'filetoinstall'],
stdout=open(os.devnull,'wb'), stderr=STDOUT)
在这种情况下,将 stdout
转储到 /dev/null
或 os.devnull
.
Dump the stdout
to /dev/null
, or os.devnull
in this case.
os.devnull
是平台无关的,在 POSIX 上返回 /dev/null
,在 Windows 上返回 nul
(这不相关,因为您正在使用 apt-get
但是,还是很高兴知道 :) )
os.devnull
is platform independent, and will return /dev/null
on POSIX and nul
on Windows (which is not relevant since you're using apt-get
but, still good to know :) )