I want to run sudo command from within my python module and provide the password inside the python code. Here are my unsuccessful attempts:
output = subprocess.Popen(['sudo', 'make', 'install'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
print output.communicate('mypass\n')
It asks password from console window (Then I do not want). Then I tried:
output = subprocess.Popen(['sudo', 'make', 'install'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
output.stdin.write('mypass\n')
output.stdin.close()
output.wait()
Again it asks password. Then I tried:
os.popen("sudo make install", 'w').write('mypass')
It again asks for password. What's wrong with my code. I tried all above attempt after doing some search in internet and it seems like they should work.