diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-05-15 17:22:25 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-05-15 17:22:25 +0200 |
| commit | f63ac8afd8110d3fcea9dd1f7eb2b8175f4ac306 (patch) | |
| tree | c70e9e150b77bd4a2b3ca9a3469fb1b89b6c97f6 | |
| parent | 53d42fdc5badea16ca76590bebd9bbb1e80c5f86 (diff) | |
| download | allocbench-f63ac8afd8110d3fcea9dd1f7eb2b8175f4ac306.tar.gz allocbench-f63ac8afd8110d3fcea9dd1f7eb2b8175f4ac306.zip | |
add function to prefix cmd with abspath using whereis
| -rw-r--r-- | src/util.py | 18 |
1 files changed, 18 insertions, 0 deletions
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 |
