Skip to content

Instantly share code, notes, and snippets.

@yangyang5214
Created November 29, 2021 13:00
Show Gist options
  • Save yangyang5214/988ed5222895d4d8ebc27fbaed8b00b3 to your computer and use it in GitHub Desktop.
Save yangyang5214/988ed5222895d4d8ebc27fbaed8b00b3 to your computer and use it in GitHub Desktop.
[run system cmd] #python #subprocess
import logging
import subprocess
def run_system_cmd(cmd):
"""
运行系统命令,并返回输出
:param cmd:
:return:
"""
out, error = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).communicate()
if error:
logging.error("run_system_cmd: {}, error: {}".format(cmd, error))
return False, None
return True, out.decode('utf-8').strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment