From f63ac8afd8110d3fcea9dd1f7eb2b8175f4ac306 Mon Sep 17 00:00:00 2001 From: Florian Fischer <florian.fl.fischer@fau.de> Date: Wed, 15 May 2019 17:22:25 +0200 Subject: [PATCH] add function to prefix cmd with abspath using whereis --- src/util.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/util.py b/src/util.py index b9f3ce6..812d980 100644 --- a/src/util.py +++ b/src/util.py @@ -1,4 +1,5 @@ import os +import subprocess import sys import src.globalvars @@ -23,6 +24,23 @@ def find_cmd(cmd): return None +def prefix_cmd_with_abspath(cmd): + """Prefix cmd with the abspath of the first word + + Usefull if cmd should be executed by the loader of a custom glibc.""" + + binary_end = cmd.find(" ") + binary_end = None if binary_end == -1 else binary_end + + cmd_start = len(cmd) if binary_end == None else binary_end + + binary_abspath = subprocess.run(["whereis", cmd[0:binary_end]], + stdout=subprocess.PIPE, + universal_newlines=True).stdout.split()[1] + + return binary_abspath + " " + cmd[binary_end:] + + def allocbench_msg(color, *objects, sep=' ', end='\n', file=sys.stdout): if src.globalvars.verbosity < 0: return -- GitLab