python - 如何让python和linux shell交互?

标签 python shell

现在,这是我在 shell 中运行的可执行程序。但它需要参数。如何使用 python 将参数传递给 shell 中的程序。我知道 unix 中有一个名为“expect”的工具,它可以与现有软件交互。我想知道python能不能做同样的事情!我的英文不好~sorry~

最佳答案

使用 subprocess模块。基本示例:

>>> import subprocess as sub
>>> sub.call(["ls", "-l"])

基本上,您可以将命令及其参数作为字符串列表传递。


编辑: 再次阅读您的问题我想知道 pexpect确实是你想要的。

关于python - 如何让python和linux shell交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8646511/

相关文章:

linux - 以 root 身份在脚本中间运行命令

linux - 如何比较 bash 中的两个配对列表?

python - Eclipse - Python 和 Ipython?

python - 如何使用 anaconda 为 python 安装 google.cloud automl_v1beta1?

python - Rabbitmq错误: [Errno 10054] An existing connection was forcibly closed by the remote host

linux - 使用 bash 进行文本操作

c - 在C中将文件路径解析为可执行文件

c# - 尝试从 Chrome 实现拖放 Gmail 附件

python html邮件失败

python - 将Python移植到D : urllib