Skip to content

Instantly share code, notes, and snippets.

@XDo0
Last active January 11, 2022 07:38
Show Gist options
  • Save XDo0/2c1765118e61fc882a6594cc5483ac3e to your computer and use it in GitHub Desktop.
Save XDo0/2c1765118e61fc882a6594cc5483ac3e to your computer and use it in GitHub Desktop.
2 funcs to run cmd import subprocess (python)
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
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