python - 从 python 调用 yeoman 生成器?

标签 python django yeoman popen

我需要在我一直在开发的 Web 应用程序中通过 Python 调用此生成器。最初我是通过向生成器发送"is"来做到这一点的,但我需要对第一个选项说“不”。

yes | yo angular --no-insight

现在我将文件的输出发送到生成器以告诉它进入

cat input.txt | yo angular --no-insight

输入.txt

n
y
y

这很好用,但我还需要存储日志,所以我将输出重定向到 out.txt

cat input.txt | yo angular --no-insight > out.txt

这就是问题所在,如我所料,第一个提示的回答是“否”,然后一切都停止了。

我需要一种以编程方式运行生成器的方法,我认为使用适配器是解决方案,但似乎绝对没有编写一个的文档。

我应该怎么做才能适合我的用例?

编辑:这是我已经用来运行命令的 popen 调用

        Popen("cat input.txt | yo angular --no-insight", shell=True).wait()

运行命令的类在其自己的线程上,因此等待几分钟不是问题。然而,我可能会在未来的更新中删除它,以在出现任何问题时处理生成器的超时。

最佳答案

你能用python的subprocess module吗? :

with open('out.txt', 'w') as file_output:
    file_output.write(subprocess.check_output('cat input.txt | yo angular --no-insight', shell=True))

您也可以只创建一个 Popen 对象到 'yo angular --no-insight' 并写入 stdin 并从 stdout 读取。

关于python - 从 python 调用 yeoman 生成器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28307387/

相关文章:

Python 等效于 ActionScript 的 apply()/call() 方法?

python - _tkinter 模块未找到

node.js - 没有创建 bower_modules 文件夹

ruby - 命令 'grunt server' 的 compass 错误

python - BottlePy 和 GEVENT 出现 SSL 错误

python - 将 send_mail() 方法更改为 EmailMessage - Django 1.6

python - 由属性确定的唯一数据库条目

python - 从 horizo​​n 中的 keystone 获取授权 token

phantomjs - Yeoman 生成器总是出错

python - 当 timedelta.days 小于 1 时,在 python 中确定 "days"