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

请问怎样用 Python 去执行 sh 文件比较好呢??

  •  
  •   meteor2013 · May 24, 2016 · 4290 views
    This topic created in 3816 days ago, the information mentioned may be changed or developed.
    比如有个 sh 文件 test.sh , 运行每次只能输入一个句子:
    $ echo 'this is the first sentence' | test.sh


    如果有 100 个句子,我想用 Python 去循环运行这个 test.sh ,应该在 Python 里面怎样执行 sh 文件呢?
    9 replies  •  2016-05-31 13:15:46 +08:00
    xiaket
    xiaket
    May 24, 2016 via iPhone
    1
    循环调 sh 这个库
    meteor2013
    meteor2013
    OP
    May 24, 2016 via iPhone
    2
    @xiaket 能说具体点吗
    dphdjy
    dphdjy
    May 24, 2016 via Android
    3
    keyword: Python shell subprocess
    congeec
    congeec
    May 24, 2016
    4
    其实用 shell 最简单
    python 里面 os.system 也简单粗暴
    ``` Python
    for i in sentences:
    os.system('echo ' + i + ' | test.sh')
    ```
    aristotll
    aristotll
    May 24, 2016
    5
    @congeec os.system 不推荐用了吧
    congeec
    congeec
    May 24, 2016
    6
    @aristotll 自己用的一次性脚本,又没啥安全问题
    quxw
    quxw
    May 24, 2016
    7
    ipython

    !source test.sh
    playniuniu
    playniuniu
    May 25, 2016❤️1
    8
    python 有个第三方库就叫做 sh , pip install sh 自己看看官方文档,非常方便
    sleshep
    sleshep
    May 31, 2016
    9
    popen
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4915 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 07:57 · PVG 15:57 · LAX 23:57 · JFK 02:57
    ♥ Do have faith in what you're doing.