I am trying to lock screen in the ubuntu server using "gnome-screensaver-command" and then unlock it by pressing enter key. This is working fine when I am doing it manually and hence thought of automating the same with Python Subprocess module.
The problem I am facing is it is locking the screen and after the timer expiry the enter key("echo -ne \n", got to know this can be used to send enter through CLI) is not happening.
Below is the code snippet.
import subprocess
import time
cmd = subprocess.call(["/usr/bin/gnome-screensaver-command", "-l"])
time.sleep(10)
subprocess.call(["echo", "-ne", "\n"])
Tried another way of doing it:
#******THIS METHOD IS NOT LOCKING THE SCREEN AT ALL*******
cmd = subprocess.Popen(["/usr/bin/gnome-screensaver-command", "-l"], stdin = subprocess.PIPE, shell=True)
time.sleep(10)
cmd.communicate(input="\n")
What should be done to work it as per my requirement ?