December 27th, 2004, 02:07 PM
is it possible to start apache with python, I tried:
os.system('sudo /usr/sbin/apachectl start')
and the code returned is 256
thanks for any help
December 27th, 2004, 03:13 PM
The default behaviour for sudo is to prompt for your user password before executing the command, which the os.system function cannot handle. You also need to have permission to run the command in the /etc/sudoers file. To see what commands you have permission to execute, type 'sudo -l'.
To send the password you need to use an interactive session with a tool like [url=http://pexpect.sourceforge.net]pexpect[url]. Using pexpect you can write a function to send the apachectl command, wait for the "Password:" prompt, then send the password. Alternatively if you have write access to the sudoers file then you can configure it not to prompt for a password, which should get round the need to use pexpect.
Dave - The Developers' Coach