Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106356
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Failed to update the os.environ with subprocess.Popen. |
| Date | 2016-04-03 18:20 +1000 |
| Message-ID | <mailman.394.1459671641.28225.python-list@python.org> (permalink) |
| References | <57009af2$0$1607$c3e8da3$5496439d@news.astraweb.com> |
On 03Apr2016 14:24, Steven D'Aprano <steve@pearwood.info> wrote:
>On Sun, 3 Apr 2016 01:29 pm, Hongyi Zhao wrote:
>> I use the following code to update the os.environ with subprocess.Popen:
>
>I don't understand what you are trying to do here. But regardless of your
>intention, the problem you have is nothing to do with updating os.environ.
>Proof: change the last line from this complicated expression:
>
>os.environ.update(line.partition('=')[::2] for line in output.split('\0'))
>to this simple expression:
>output.split('\0')
>
>and you will get the same error. os.environ is irrelevant. Your problem is
>only with Popen.
>
>What makes you think that Popen objects have a split() method? They are not
>documented as having this method:
>
>https://docs.python.org/2/library/subprocess.html
>https://docs.python.org/3/library/subprocess.html
>https://pymotw.com/2/subprocess/
In particular, you want the subprocess' output. As written, your code sets
"output" to the Popen object. You actually want to set it to the .stdout
attribute of that object, which is the output from the subcommand.
Cheers,
Cameron Simpson <cs@zip.com.au>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Failed to update the os.environ with subprocess.Popen. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-04-03 03:29 +0000
Re: Failed to update the os.environ with subprocess.Popen. Steven D'Aprano <steve@pearwood.info> - 2016-04-03 14:24 +1000
Re: Failed to update the os.environ with subprocess.Popen. Cameron Simpson <cs@zip.com.au> - 2016-04-03 18:20 +1000
Re: Failed to update the os.environ with subprocess.Popen. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-04-03 11:24 +0000
Re: Failed to update the os.environ with subprocess.Popen. Cameron Simpson <cs@zip.com.au> - 2016-04-04 07:49 +1000
csiph-web