V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-04-27 17:44:42 +08:00 · 2156 次点击
    这是一个创建于 3287 天前的主题,其中的信息可能已经有所发展或是发生改变。
    呃,这标题有点拗口。举个例子:

    使用 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 条回复    2015-04-27 17:59:57 +08:00
    clino
        1
    clino  
       2015-04-27 17:59:57 +08:00   ❤️ 1
    可以参考我之前发的 t/126248
    这个因为用了gevent可以支持并发,如果你没有并发的需要可以参考里面的 print_stdout print_stderr
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2845 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:47 · PVG 14:47 · LAX 23:47 · JFK 02:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.