Last active
January 11, 2022 07:38
-
-
Save XDo0/2c1765118e61fc882a6594cc5483ac3e to your computer and use it in GitHub Desktop.
2 funcs to run cmd import subprocess (python)
This file contains 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
from subprocess import PIPE,Popen | |
import logging | |
logger = logging.getLogger('dev.utils') | |
logger.setLevel(logging.WARNING) | |
logging.basicConfig(filename='./log/'+datetime.now().strftime(f'{__file__}_%H_%M_%d_%m_%Y.log'), | |
filemode='a', | |
level=logging.WARNING, | |
format='%(asctime)s %(message)s', | |
datefmt='%d %b %Y %H:%M:%S') | |
''' | |
cmd=list() | |
e.g.,["./jadx","-d",...] | |
''' | |
def get_cmd(cmd): | |
p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False) | |
try: | |
output = '' | |
output, stderr = p.communicate() | |
finally: | |
if stderr: | |
logger.error(f"[ERROR] Popen: {stderr}") | |
#return output.splitlines() | |
return output |
This file contains 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 subprocess | |
''' | |
cmd=list() | |
e.g.,["./jadx","-d",...] | |
''' | |
def run_cmd(cmd): | |
ret = subprocess.run(cmd,encoding="utf-8",timeout=1) | |
if ret.returncode == 0: | |
print("success:", ret) | |
else: | |
print("error:", ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment