推荐学习书目
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
uti6770werty
V2EX  ›  Python

Win 下面持续跑 Python 程序,用什么 console-line 软件好?

  •  
  •   uti6770werty · Dec 2, 2019 · 4407 views
    This topic created in 2400 days ago, the information mentioned may be changed or developed.

    pycharm 的 console 输出似乎也回滚不了 8000 行以前的输出内容
    pycharm 一运行后,自身也挺占内存的
    不考虑 cmd.exe ,IDLE
    1、主要是想记录输出的内容。。。
    2、不考虑修改程序本身的 logging 完成输出内容。。。
    目前在用 PowerCMD,感觉一般般,就是上面提到的 console 输出记录不好用。。。

    18 replies    2019-12-13 18:07:07 +08:00
    charlie21
        1
    charlie21  
       Dec 2, 2019 via Android
    python 1.py > output.txt
    zhzy
        2
    zhzy  
       Dec 2, 2019 via iPhone
    不能重定向么
    senninha
        3
    senninha  
       Dec 2, 2019
    git 自带的 mintty 环境运行 py,重定向到文件完事。
    wuwukai007
        4
    wuwukai007  
       Dec 2, 2019 via Android
    pycharm 最离谱的是重启代码,控制台会清空
    Nasei
        5
    Nasei  
       Dec 2, 2019
    重定向好像程序结束前是看不到结果的,你是持续运行的话,我觉得可以用 docker 的 windows container,有 python 的镜像,然后 docker log 看
    exip
        6
    exip  
       Dec 2, 2019 via Android
    jupyter lab 或 notebook 几万行的输出都没问题
    lhx2008
        7
    lhx2008  
       Dec 2, 2019 via Android
    不知道有没有像 linux 里面一个输出流变两个的,我觉得理论上应该有
    xml123
        8
    xml123  
       Dec 2, 2019
    tee.exe ?
    Jirajine
        9
    Jirajine  
       Dec 2, 2019 via Android   ❤️ 1
    @Nasei
    $python xx.py > log.log &
    $tail -f log.log
    lniwn
        10
    lniwn  
       Dec 2, 2019
    cmder ?
    youngxhui
        11
    youngxhui  
       Dec 2, 2019
    vscode + wsl + jupyter

    ![Snipaste_2019-12-02_22-45-47.png]( https://i.loli.net/2019/12/02/fTPzl79at5SxNuo.png)
    imycc
        12
    imycc  
       Dec 2, 2019
    如果你装了 git bash 的话,

    # 将 test.py 的标准输出和错误全重定向到 test.log 中,并在后台执行
    python test.py > test.log 2>&1 &

    # 查看输出
    tail -f test.log

    不过要注意一个问题,如果你是用 print 打日志的话,tail -f 可能无法及时看到输出(在缓冲区里还没写进文件)
    BBCCBB
        13
    BBCCBB  
       Dec 2, 2019
    python 自带的 logging 输出到文件也就几行代码得事情..
    crclz
        14
    crclz  
       Dec 2, 2019
    docker
    levelworm
        15
    levelworm  
       Dec 3, 2019
    直接用 log 库输出可行么?
    PolarBears
        16
    PolarBears  
       Dec 3, 2019
    重定向输出到文本文件然后 Get-Content -Tail 0 -Wait file.log
    ClericPy
        17
    ClericPy  
       Dec 3, 2019
    Windows 用服务跑不好么
    git-bash 基于 mintty 的, 兼容性比较好, 少数情况会遇到一些 win32 独有的兼容问题(比如 exe 程序), 这种时候我用的是 cmder
    如果你那边 logger 定的好, 这都不是问题
    如果 logger 不完整, 想重定向所有 stdout stderr, 除了用上面那个 git-bash 的 > 操作符, 可以考虑重绑定 sys.stdout sys.stderr 到你自己的类, 很多年以前我就这么干过

    https://paste.ubuntu.com/p/3mjY9q8Nvn/
    chaogg
        18
    chaogg  
       Dec 13, 2019
    我直接用的 cmd.exe 也没问题,还能看输出
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6228 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 77ms · UTC 03:08 · PVG 11:08 · LAX 20:08 · JFK 23:08
    ♥ Do have faith in what you're doing.