Using module 'subprocess' with timeout

后端 未结 29 2428
旧巷少年郎
旧巷少年郎 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:02

    if you are using python 2, give it a try

    import subprocess32
    
    try:
        output = subprocess32.check_output(command, shell=True, timeout=3)
    except subprocess32.TimeoutExpired as e:
        print e
    

提交回复
热议问题