Created
November 29, 2021 13:00
-
-
Save yangyang5214/988ed5222895d4d8ebc27fbaed8b00b3 to your computer and use it in GitHub Desktop.
[run system cmd] #python #subprocess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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