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

David bouncingcats at gmail.com
Fri Aug 9 11:56:28 EDT 2013


On 9 August 2013 23:21, Adam Mercer <ramercer at gmail.com> wrote:
> On Thu, Aug 8, 2013 at 11:47 PM, David <bouncingcats at gmail.com> wrote:
>
>> At a quick glance, I have a couple of suggestions.
>>
>>>   command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
>>
>> sudo doesn't work like this. It doesn't read from standard input. You
>> need to supply the command as an argument to sudo. Get the sudo syntax
>> correct by learning to use it in a shell (eg terminal running bash )
>> before trying to use it from python code.
>
> The above does works in the terminal:

Ah, sorry, I didn't pay close attention to what you are doing (with tee).

>> So, if you figure out how to use sudo without '|' you will solve both
>> these issues.

At least I wasn't 100% wrong :)
Anyway I'm glad some smarter people helped you.



More information about the Python-list mailing list