#coding=utf-8 import os import sys import re import subprocess #return exitcode value + output message: # 0: succ # 1: error def system_cmd_run(cmd_str): dangerous_cmd = {"rm", "mv", "poweroff", "shutdown"} for cmd in dangerous_cmd: pattern = "\s*%s" %(cmd) match_str = re.match(pattern, cmd_str) if not match_str is None: print("can't run this cmd:%s" %(cmd_str)) sys.exit(1) try: exitcode, output = subprocess.getstatusoutput(cmd_str) except Exception as e: #if exitcode != 0: # output = "" return 1, e return exitcode, output