Skip to content

Instantly share code, notes, and snippets.

@widlarizer
Last active March 8, 2024 14:34
Show Gist options
  • Save widlarizer/b386a08426fe8712818c2a10614be0bc to your computer and use it in GitHub Desktop.
Save widlarizer/b386a08426fe8712818c2a10614be0bc to your computer and use it in GitHub Desktop.
Python r function: run commands even easier than in bash
import subprocess, functools
# Do you often use Python in place of bash?
# Do you want to simply just run thing and get output?
# Here's a wrapper function for automating whatever you'd like.
# Use shell=True and you can use pipes and env vars!
# Throw in a string! Throw in an arg list! Throw in a pathlib.Path maybe!
# Use it everywhere! 3 bazillion devices run r('foo')!
r = functools.partial(subprocess.check_output, text=True)
# Copyright © 2024 HighTec EDV Prague s.r.o.
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment