How to escape os.system() calls? May 15, 2022 by Tarik shlex.quote() does what you want since python 3. (Use pipes.quote to support both python 2 and python 3)