Skip to content

Instantly share code, notes, and snippets.

@pgp
Created January 8, 2020 12:04
Show Gist options
  • Save pgp/d5e378b72015d8adb1926a0c572cd0be to your computer and use it in GitHub Desktop.
Save pgp/d5e378b72015d8adb1926a0c572cd0be to your computer and use it in GitHub Desktop.
Programmatically use sudo from python
import subprocess
sudoPassword = b'mySudoPassword\n'
cmd = 'sudo -S touch /dev/shm/1.txt'.split(' ')
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.communicate(sudoPassword)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment