I'm using Popen together with custom environment variables. My expectation is when I run something like this:
proc = Popen(
command,
universal_newlines=True,
bufsize=0,
shell=False,
env=env,
)
that the environment variables set when running command are exactly the contents of env. However, when I run this on windows machines on github actions, there's (exactly) two additional variables set: TERM=xterm-256color, and HOME=/c/Users/runneradmin. Interestingly, when I check the contents of os.environ before execution, there's a lot of variables on the host environment set, except those two.
This only happens on windows (running windows-latest). On Mac and Linux, the environment is exactly the contents of env.
The command I'm running in this case is env which outputs the environment variables.
My question is, where do those two variables come from and how do I get rid of them?
This seems to be because GH Actions
cmd.exeis not really thecmdyou would expect it to be, but a terminal emulator.You can verify it with this:
uname -a(a linux command) will print out something like this:MSYS is a windows terminal emulator, that provides a lot of capabilities for building different software on Windows, which is probably why GH Actions uses it by default. It also allows you to run several linux commands on the same terminal, for example the
envcommand you mentioned.It will also set some default env variables, like
TERM=xterm-256color, which enables colors to the terminal emulator.Popen()will then try to use this default cmd, which is why those environment variables are then pre-set when you runenv.