Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52270

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

From Nobody <nobody@nowhere.com>
Subject Re: Using sudo to write to a file as root from a script
Date 2013-08-09 21:12 +0100
Message-Id <pan.2013.08.09.20.12.19.320000@nowhere.com>
Newsgroups comp.lang.python
References <mailman.383.1376022002.1251.python-list@python.org>
Organization Zen Internet

Show all headers | View raw


On Thu, 08 Aug 2013 23:11:09 -0500, Adam Mercer wrote:

> I'm trying to write a script that writes some content to a file root
> through sudo, but it's not working at all. I am using:

>   command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]

You can't create a pipeline like this. All of the list elements after the
first will be passed as arguments to "echo".

Try:

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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Using sudo to write to a file as root from a script Adam Mercer <ramercer@gmail.com> - 2013-08-08 23:11 -0500
  Re: Using sudo to write to a file as root from a script Denis McMahon <denismfmcmahon@gmail.com> - 2013-08-09 04:36 +0000
  Re: Using sudo to write to a file as root from a script Nobody <nobody@nowhere.com> - 2013-08-09 21:12 +0100
    Re: Using sudo to write to a file as root from a script Nobody <nobody@nowhere.com> - 2013-08-09 21:16 +0100

csiph-web