I have a problem when I want to fake an input for the next bash prompt, the following code is running correctly :
import subprocess
who = subprocess.Popen(["who"], stdout=subprocess.PIPE)
grep = subprocess.Popen(["grep", "lefevrmh2"], stdin=who.stdout, stdout=subprocess.PIPE)
who.stdout.close()
awk = subprocess.Popen(["awk", "{ print $2 }"], stdin=grep.stdout, stdout=subprocess.PIPE)
grep.stdout.close()
head = subprocess.Popen(["head", "-n", "1"], stdin=awk.stdout, stdout=subprocess.PIPE)
awk.stdout.close
tty = head.communicate()[0].decode().rstrip()
import fcntl
import termios
print("/dev/"+tty)
with open("/dev/"+tty, 'w') as fd:
for c in "Salut!!":
fcntl.ioctl(fd, termios.TIOCSTI, c)
My problem is when I run this on sudo (not sudo su), even if I fetch the right tty for the original user, it doesn’t write in the input when sudo quit, how can this works ?
New contributor
Matth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.