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.exe
is not really the cmd
you would expect it to be, but a terminal emulator.
You can verify it with this:
- name: "Print shell"
shell: cmd
run: |
uname -a
env
uname -a
(a linux command) will print out something like this:
MSYS_NT-10.0-20348 fv-az1702-301 3.4.10-87d57229.x86_64 2024-02-14 20:17 UTC x86_64 Msys
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 env
command 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 run env
.