Closed chaselgrove closed 4 years ago
my workaround idea was to dump + parse /proc/PID/environ
- but it seems there is no /proc
on osx (mach), so would be only linux specific
@kyleam : perl -e "print %ENV"
@chaselgrove and I discussed this a bit on the call. A couple of points:
We talked about why, if we're going to dump the environment with a language, perl should be preferred to python. I said I thought the thinking was that it's more likely that minimal resources/containers will have perl. I think @chaselgrove was unconvinced, and, thinking about it more, I'm not sure that really holds water in general. While it's true that debian:*-slim has perl but not python, other minimal images like alpine and busybox have neither (nor do they have an env
that supports -0
). And I suspect it'd be quite rare for a server to not have some version of python.
@chaselgrove mentioned that using python/perl to grab the values would mean non-exported variables aren't included. But that's the case with env
anyway at least on my system (i.e. with GNU coreutil's env
). So I think that's okay.
Anyway, here are my two snippets to imitate env -0
:
python -c "import os; import sys; sys.stdout.write('\0'.join('{}={}'.format(k, v) for k, v in os.environ.items()))"
perl -e 'foreach (keys %ENV) {print "$_=$ENV{$_}\0";}'
perl is the winner! ;-) @chaselgrove please run perl version if env -0
fails
reproman/resource/session.py uses
env -0
to get the environment, but-0
is not a supported option toenv
on macOS.