Using module 'subprocess' with timeout

后端 未结 29 2398
旧巷少年郎
旧巷少年郎 2020-11-21 15:15

Here\'s the Python code to run an arbitrary command returning its stdout data, or raise an exception on non-zero exit codes:

proc = subprocess.P         


        
29条回答
  •  借酒劲吻你
    2020-11-21 16:00

    I added the solution with threading from jcollado to my Python module easyprocess.

    Install:

    pip install easyprocess
    

    Example:

    from easyprocess import Proc
    
    # shell is not supported!
    stdout=Proc('ping localhost').call(timeout=1.5).stdout
    print stdout
    

提交回复
热议问题