Hi guys and gal's I have a problem.
I'm executing a python script that needs to run a sudo command to continue. This is the command:
sudo /etc/init.d/test restart
The issue is that no matter how I execute this it only runs sudo and /etc/init.d/test and returns:
sudo: /etc/init.d/test: command not found
The issue seems to be that restart is not sent along with the command.
These are the ways I've tried running the command:
Attempt 1 using os
os.system('sudo /etc/init.d/test restart')
Attempt 2 using subprocess
x = subprocess.Popen(['sudo','/etc/init.d/test','restart'])
x.communicate()
Attempt 3 using subprocess again
x = subprocess.Popen(['sudo','/etc/init.d/test restart'])
x.communicate()
This actually returned:
sudo: /etc/init.d/test restart: command not found
Which doesn't make sense since if I execute the command directly on the system it works.
Any ideas as to how I could do this?