我正在尝试通过 Ubuntu Linux 中的 Python 子进程模块通过 apt-get 自动安装 tripwire。我遇到的问题是,在安装过程中,Tripwire 提示我进行 Postfix 邮件配置,通过安装 apt-get 后出现的不同配置页面集(见附图)设置 site.key 和 local.key。
如何使用子流程模块与这些页面进行交互?
from subprocess import *
p=Popen("apt-get install tripwire",stdout=PIPE,stdin=PIPE,stderr=PIPE,shell=True)
p.communicate(input="Y\n") # Y = Yes to confirm installation of the package through apt-get
我尝试使用“stdin=PIPE”,但在与这些终端页面交互时遇到了一些挑战:
这些页面在包下载完成后出现 配置,所以我必须为 要出现的页面
此外,我需要实现向上和向下箭头键来选择各种选项。
谢谢
约翰
最佳答案
启动安装并启用自动确认和安静模式并设置 this flag :
export DEBIAN_FRONTEND=noninteractive
apt-get install -y -q tripwire
这样您就不需要与安装后的配置进行通信。
您还可以使用 -c
传递预先存在的 config
文件(或使用 -o
指定配置选项)。
我可能会尝试:
from subprocess import call
p = call(["apt-get", "install", "-y", "-q", "-c", "config.cfg", "tripwire", shell=False])
关于python - 在 Linux 中通过 python 自动安装 tripwire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419629/