python - 如何在 python 中自动回答"is"?

标签 python debian apt

假设我有一个运行 apt update -y 的脚本,稍后我需要针对不同的软件包手动回答这些问题。我怎样才能自动做到这一点?

设置 virtualbox-guest-x11 (5.0.32-dfsg-0ubuntu1.16.04.2) ...

Configuration file '/etc/X11/Xsession.d/98vboxadd-xclient'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** 98vboxadd-xclient (Y/I/N/O/D/Z) [default=N] ?  conffile prompt detected: /etc/X11/Xsession.d/98vboxadd-xclient /etc/X11/Xsession.d/98vboxadd-xclient.dpkg-new

我的脚本能够检测配置提示,但我应该如何自动回答"is"?

通过使用 python-apt api,我可以通过此函数检测提示

def conffile(self, current, new):
    print " conffile prompt detected: %s %s" % (current, new)

    """(Abstract) Called when a conffile question from dpkg is detected."""

最佳答案

使用yes命令:

yes Y | apt ...

关于python - 如何在 python 中自动回答"is"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43316879/

相关文章:

Python,从类方法中删除列表项

python - python3中将十六进制转换为base64的基本方法

python - 导入错误 : Entry point ('zc.buildout' , 'default' )未找到

dependencies - libstdc++6-armhf-cross 出现未满足的依赖项错误。如何解决?

python - 在没有互联网连接的情况下运行 sudo apt-get install

python - 根据其他两列中的值,用另一个数据框中的值填充一个数据框中的新列? ( python / Pandas )

python - IPython 笔记本上 CSV 文件的 SQL 语句

linux - 我应该如何安装 Debian 上的 Ubuntu 存储库中通常提供的软件包

node.js - E : Unable to locate package npm

linux - 亚马逊 Linux : "apt-get: command not found"