我需要在我一直在开发的 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/