Python, subprocess, call(), check_call and returncode to find if a command exists

后端 未结 3 2096
执笔经年
执笔经年 2021-02-07 04:35

I\'ve figured out how to use call() to get my python script to run a command:

import subprocess

mycommandline = [\'lumberjack\', \'-sleep all night\', \'-work a         


        
3条回答
  •  深忆病人
    2021-02-07 04:56

    A simple snippet:

    try:
        subprocess.check_call(['executable'])
    except subprocess.CalledProcessError:
        pass # handle errors in the called executable
    except OSError:
        pass # executable not found
    

提交回复
热议问题