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
aias
V2EX  ›  Python

fail 命令在 os.popen 中是不能执行的?

  •  1
     
  •   aias · 2016-05-17 17:35:35 +08:00 · 2124 次点击
    这是一个创建于 2907 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import os
    os.popen("tail -f /root/projects/***/***/logs/application.log")
    <open file 'tail -f /root/projects/***/***/logs/application.log', mode 'r' at 0x7f36bd7c9390>
    
    4 条回复    2016-05-19 07:42:25 +08:00
    aias
        1
    aias  
    OP
       2016-05-17 17:39:26 +08:00
    os.popen("tail -f /root/projects/***/***/logs/application.log",“ r ”)直接没反应了..
    aias
        2
    aias  
    OP
       2016-05-17 17:40:37 +08:00
    还是不行..
    binux
        3
    binux  
       2016-05-17 18:03:06 +08:00
    In [1]: import os

    In [2]: f = os.popen("tail -f ./domains.txt")

    In [3]: f.readline()
    Out[3]: 'www.thephonebook.bt.com\n'

    In [4]: f.read(10)
    Out[4]: 'www.chambe'

    In [5]: f.readline()
    Out[5]: 'rofcommerce.com\n'
    aias
        4
    aias  
    OP
       2016-05-19 07:42:25 +08:00
    @binux 感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   869 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:02 · PVG 07:02 · LAX 16:02 · JFK 19:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.