I am attempting to execute sudo -S id within a TTY shell using pty.spawn() in python 2.7.
import os
import pty
command = 'id'
scmd ="sudo -S %s"%(command)
def reader(fd):
return os.read(fd, 50)
def writer(fd):
yield 'password'
yield ''
pty.spawn(scmd, reader, writer)
when I execute the above code the python interpreter outputs the following error:
OSError: [Errno 13] Permission denied
My code is based on this answer: Issuing commands to psuedo shells (pty)
Even when the password is correct I receive the above error, how do I fix this code so that it executes sudo and prints the output of the id command to stdout?