I've a service written in Python that can receive commands and does things, here is how it is built:
print("\nWelcome!\n")
for line in sys.stdin:
cmd=line.rstrip()
if cmd == "ls" or cmd == "help":
print("Available Commands:")
Now this service is started with systemd
and its unit file has the following:
[Service]
Environment=PYTHONUNBUFFERED=1
ExecStart=...service.py
WorkingDirectory=...
StandardOutput=tty
StandardInput=tty-force
TTYVHangup=yes
TTYPath=/dev/tty60
TTYReset=yes
So the service input and output is attached to the tty60
. I can use conspy 60
to see what the service is doing and interact with it. For instance here I typed test
and then help
:
test
Error: command 'test' not found.
Type 'help' for a list of available commands.
help
Avaliable Commands:
> status, fan1, fan2, fan3, fan4, wake, sleep, quit
Python is able to grab what I typed and answers as expected.
Now, how can I send a command to the tty
without entering an interactive program like conspy
?
I tired echo -e "ls\n" >> /dev/tty60
and in another terminal with conspy
I can see the command but Python didn't process it:
help **---> sent via conspy**
Avaliable Commands:
> status, fan1, fan2, fan3, fan4, wake, sleep, quit
help **---> sent with "echo"**
As you can see the last help
sent via echo
wasn't processed.
Thank you.