Skip to content

Instantly share code, notes, and snippets.

@SVilgelm
Last active July 22, 2019 13:16
Show Gist options
  • Select an option

  • Save SVilgelm/ea459b4b195cee16c54d882f9f83c020 to your computer and use it in GitHub Desktop.

Select an option

Save SVilgelm/ea459b4b195cee16c54d882f9f83c020 to your computer and use it in GitHub Desktop.
Shell sanitizing, quoting parameters
try: # py3
from shlex import quote # noqa
except ImportError: # py2
from pipes import quote # noqa
def format_cmd(cmd, *args, **kwargs):
return cmd.format(*[quote(str(i)) for i in args],
**{k: quote(str(v)) for k, v in kwargs.items()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment