python - 从 Python 程序向命令行提示符发送输入

标签 python starcluster

我认为这是一个非常简单的问题,但我一直未能找到一个简单的答案。

我正在运行一个终止 AWS 集群的 python 程序(使用 starcluster)。我只是使用子进程从我的 python 程序调用命令,如下所示。

subprocess.call('starcluster terminate cluster', shell=True)

实际命令在很大程度上与我的问题无关,但提供了一些上下文。此命令将开始终止集群,但会在继续之前提示输入是/否,如下所示:

Terminate EBS cluster (y/n)? 

如何从我的 python 程序中自动输入 yes 作为此提示的输入?

最佳答案

同时 possible to do with subprocess alone in somewhat limited way , 我会选择 pexpect对于这样的互动,例如:

import pexpect
child = pexpect.spawn('starcluster terminate cluster')
child.expect('Terminate EBS cluster (y/n)?')
child.sendline('y')

关于python - 从 Python 程序向命令行提示符发送输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28032457/

相关文章:

python - 主成分分析最重要的原始特征

python - Makefile 无法运行源命令

hadoop - MIT StarCluster 和 S3

windows - starcluster easy_install windows

python - 如何访问和修改 Django 模板上下文变量

python - anaconda3/bin/python : undefined symbol: archive_errno

python - 如何在二维图像的一个点旋转后找到平移值?

python - Sun Grid Engine,强制每个节点执行一项作业

sungridengine - 确保 Star Cluster/SunGridEngine (AGE) 上的每个节点一个作业

python - 如何动态扩展 StarCluster/qsub/EC2 以跨多个节点运行并行作业