Atom command doesn't pass environment variables to Atom


#1

The atom script doesn’t pass environment variables to the Atom GUI application. See: https://atom.io/packages/pandoc#problems-with-path

The easiest solution is to edit the atom command and change open to env open.

This is a problem if you’re writing extensions that call external commands which it expects to find on PATH.

It’s still a problem if you launch the application outside of a terminal, but that’s more of an OS X related thing.


Cedilha accent problem (ç)
#2

I’ve opened up an issue on the Atom repo to fix this. Thanks for reporting it.


#3

+1 - I have this issue in the language-go repo, executing gofmt


#4

+1 - Working on a jsfmt plugin and having issues loading the $PATH properly.


#5

I actually just ended up working around this bug in my script runner package so it works on Mac and Linux easily. You could probably use the code here and dump it into your init script for atom:


#6

So, I thought I’d add, I found that this doesn’t always get all environment variables defined in the terminal, for that you need to spawn what is called an interactive shell. I couldn’t do this using exec/execFile, I don’t know precisely what was going on but basically it would just hang.

Anyway, I found the workaround was to use spawn with detached: true. A complete working example is in the script-runner package (https://atom.io/packages/script-runner), the source code which can be found here: https://github.com/ioquatix/script-runner/blob/v1.5.0/lib/script-runner.coffee#L45-L63

This is cross platform (Mac & Linux) but does require more testing. I hope this is helpful to anyone else in the same boat, it took quite a bit of sussing out.


#7

This appears to be an issue despite the ticket being closed. I can confirm that when Atom is opened for the first time it inherits the environment correctly. However, if I open a new project using the atom command it won’t inherit the environment for that window.

This is problematic for many of my workflows where an environment variable is different based on the project I am working on. This prevents some extensions which rely on that environment variable.


#8

Can you link the ticket back here?


#9

Yeah, this is an interesting case and I did think about it.

script-runner assumes you want to use the login shell environment. This is sort of the default but you can’t, say, run rvm use jruby and then atom and expect that script-runner would use jruby. It’s unfortunate. The only way to fix this is in the startup script for atom - if it starts from a GUI it should pull in the correct environment, otherwise it should pull it in from the terminal where it was started. IMHO.


#10

The Github issue: https://github.com/atom/atom/issues/1614