diff --git a/src/python/m5/main.py b/src/python/m5/main.py index 4701dfa5ea..ddcb024f8b 100644 --- a/src/python/m5/main.py +++ b/src/python/m5/main.py @@ -496,10 +496,23 @@ def main(): % (socket.gethostname(), os.getpid()) ) - # in Python 3 pipes.quote() is moved to shlex.quote() - import pipes + def quote(arg: str) -> str: + """Quotes a string for printing in a shell. In addition to Unix, + this is designed to handle the problematic Windows cases where + 'shlex.quote' doesn't work""" - print("command line:", " ".join(map(pipes.quote, sys.argv))) + if os.name == "nt" and os.sep == "\\": + # If a Windows machine, we manually quote the string. + arg = arg.replace('"', '\\"') + if re.search("\s", args): + # We quote args which have whitespace. + arg = '"' + arg + '"' + return arg + import shlex + + return shlex.quote(arg) + + print("command line:", " ".join(map(quote, sys.argv))) print() # check to make sure we can find the listed script