Using sudo to write to a file as root from a script

Nobody nobody at nowhere.com
Fri Aug 9 16:16:14 EDT 2013


On Fri, 09 Aug 2013 21:12:20 +0100, Nobody wrote:

> Try:
> 
>   command = ['sudo', 'tee', config_file]
>   p = subprocess.Popen(command, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE)
>   out, _ = p.communicate('channel')

Oops; you also need stdin=subprocess.PIPE.




More information about the Python-list mailing list