Apr-02-2018, 12:45 PM
(This post was last modified: Apr-02-2018, 02:33 PM by Gribouillis.)
I have an old snippet in my notes:
import getpass import subprocess as sp COMMAND = ['ls'] mypass = getpass.getpass('This needs administrator privileges: ') proc = sp.Popen(['sudo', '-kS'] + COMMAND, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE) proc.stdin.write(mypass + '\n') o, e = proc.communicate() if proc.recurncode: print('command failed') else: print('success') print(o) print(e)