Basically I wanted to start a daemon in the background that will still prompt the user in the console for a password. I created this with pexpect, but when this program ends it kills the daemon since it is a child process. So obviously pexpect isn’t going to work for this. Does any body know of a way to do this?
#!/usr/bin/env python
import pexpect
import getpass
child = pexpect.spawn('python daemon.py &')
child.expect_exact('Password:')
passwd = getpass.getpass()
child.sendline(passwd)
index = child.expect_exact('Started Successfully')
print index
Dany suggested, “Had you considered using os.fork() and then run the daemon module?”
Your answer was “yea, but I didn’t know how to pass the password to the daemon. Have to keep the password safe i.e. not storing on the hdd and not showing it on the screen.”
But you don’t have to do anything to pass the password to the daemon. After fork, it’s still accessible. For example:
So, read the password in the parent, then fork the daemon; it already has the password, so it doesn’t need a tty for anything. Problem solved.