推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Feiox
V2EX  ›  Python

如何在 Python Shell 中执行一个 Shell 命令(该命令持续输出内容)并持续获取并显示其输出?

  •  
  •   Feiox ·
    feiox · Apr 27, 2015 · 2656 views
    This topic created in 4105 days ago, the information mentioned may be changed or developed.
    呃,这标题有点拗口。举个例子:

    使用 Flask-Script 在命令行中执行 `python manger.py startcelery`
    其中 `startcelery` 是想在 bash 中运行 `celery -A celeryd worker -P eventlet -c 1000 -l info` 命令。
    那么,如何持续获得这条命令的输出内容并显示在 shell 中呢?

    附:以上只是举个例子。不要说为什么不直接在 shell 中执行,我只是想把日常开发中所有的行为都放在 manger.py 中集中管理。另外,我也知道可以用 Fabric 完成。。。。可,Py3k ~(>_<)~
    1 replies    2015-04-27 17:59:57 +08:00
    clino
        1
    clino  
       Apr 27, 2015   ❤️ 1
    可以参考我之前发的 t/126248
    这个因为用了gevent可以支持并发,如果你没有并发的需要可以参考里面的 print_stdout print_stderr
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   993 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 167ms · UTC 22:06 · PVG 06:06 · LAX 15:06 · JFK 18:06
    ♥ Do have faith in what you're doing.