summaryrefslogtreecommitdiffstats
path: root/nsploit/util/cmd.py
blob: 5025a55875dd8c0d7e03b136bcbfd855fe2e5e60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from subprocess import run

def run_cmd(cmd,cwd=None):
    return run(cmd,cwd=cwd,capture_output=True,text=True,check=True).stdout.split('\n')[:-1]

__RUN_CACHE__ = {}
def run_cmd_cached(cmd,cwd=None):
    key = ''.join(cmd)
    if key in __RUN_CACHE__:
        return __RUN_CACHE__[key]
    else:
        result = run_cmd(cmd,cwd)
        __RUN_CACHE__[key] = result
        return result