Discussion:
How to set environment variables in IDLDE
(too old to reply)
mankoff
2011-01-11 15:56:42 UTC
Permalink
Hi,

I usually run IDL from the command line and it inherits all the
environment variables I have in my .profile. This allows me to, for
example, "spawn, 'foo'" where foo is in my unix PATH, and foo is
found. When I run the IDLDE by double-clicking on the icon, this does
not work.

I've found the suggestion to create a ~/.MacOSX/environment.plist file
and put my path there. This has caused all sorts of other problems.

Is there a way in the IDLDE, or via IDL commands (I can put them in my
startup.pro file), for me to generally get my environment into the
IDLDE or specifically append my PATH statement so that some unix tools
can be found by SPAWN?

Thanks,

-k.
FÖLDY Lajos
2011-01-11 16:25:56 UTC
Permalink
Post by mankoff
Is there a way in the IDLDE, or via IDL commands (I can put them in my
startup.pro file), for me to generally get my environment into the
IDLDE or specifically append my PATH statement so that some unix tools
can be found by SPAWN?
IDL> setenv, 'PATH='+getenv('PATH')+':mydir'

regards,
Lajos
mankoff
2011-01-11 16:39:47 UTC
Permalink
Post by FÖLDY Lajos
Post by mankoff
Is there a way in the IDLDE, or via IDL commands (I can put them in my
startup.pro file), for me to generally get my environment into the
IDLDE or specifically append my PATH statement so that some unix tools
can be found by SPAWN?
IDL> setenv, 'PATH='+getenv('PATH')+':mydir'
regards,
Lajos
Yup that works thank you!

-k.
Paulo Penteado
2011-01-11 21:08:08 UTC
Permalink
Post by mankoff
Hi,
I usually run IDL from the command line and it inherits all the
environment variables I have in my .profile. This allows me to, for
example, "spawn, 'foo'" where foo is in my unix PATH, and foo is
found. When I run the IDLDE by double-clicking on the icon, this does
not work.
But it does work if you start idlde from the terminal, right? So it
would not be an issue with the DE, it would be in the shortcut.
mankoff
2011-01-12 00:35:34 UTC
Permalink
Post by Paulo Penteado
Post by mankoff
Hi,
I usually run IDL from the command line and it inherits all the
environment variables I have in my .profile. This allows me to, for
example, "spawn, 'foo'" where foo is in my unix PATH, and foo is
found. When I run the IDLDE by double-clicking on the icon, this does
not work.
But it does work if you start idlde from the terminal, right? So it
would not be an issue with the DE, it would be in the shortcut.
It does work when launched from the terminal. It isn't an IDL issue
per se, but an issue with the way Mac passes environment inheritance.

-k.
Paulo Penteado
2011-01-12 00:49:11 UTC
Permalink
Post by mankoff
Post by Paulo Penteado
But it does work if you start idlde from the terminal, right? So it
would not be an issue with the DE, it would be in the shortcut.
It does work when launched from the terminal. It isn't an IDL issue
per se, but an issue with the way Mac passes environment inheritance.
Could it be that the variables were set in .profile after the current
desktop session started running? In GNOME, I noticed that processes
started from the menus are given a copy of the environment variables
as they were when the GNOME process was started. Which can make things
quite confusing, as a process may get variables that are not set in
the current .profile and *rc files anymore.
mankoff
2011-01-12 05:13:36 UTC
Permalink
Post by Paulo Penteado
Post by mankoff
Post by Paulo Penteado
But it does work if you start idlde from the terminal, right? So it
would not be an issue with the DE, it would be in the shortcut.
It does work when launched from the terminal. It isn't an IDL issue
per se, but an issue with the way Mac passes environment inheritance.
Could it be that the variables were set in .profile after the current
desktop session started running? In GNOME, I noticed that processes
started from the menus are given a copy of the environment variables
as they were when the GNOME process was started. Which can make things
quite confusing, as a process may get variables that are not set in
the current .profile and *rc files anymore.
I logged out/in and even rebooted after setting up environment
variables, and they are just not read from the UNIX dot files. This is
known behavior on OS X, and using ~/.MacOSX/environment.plist is a
known solution, although a buggy solution in this case. Adding/
adjusting the environment variable in the IDL startup file works fine.

-k.
Luke
2017-11-29 18:28:07 UTC
Permalink
I know this is a really old thread, but since this is where I landed in my great search on this issue.. in 2017.. I figured I'd post my solution since I cannot seem to make anything else work. This is code you can put in your startup.pro file, and it assumes you declare your environmental vars with the export command in your .bash_profile. Change the relevant lines as needed. Works like a charm for me.. after all these years of declaring pathnames explicitly for all my scripts run in my IDLDE environment.

;Set user environmental variables
file = getenv('HOME')+path_sep()+'.bash_profile'
line = ''
openr, lun, file, /get_lun
while not eof(lun) do begin & $
readf, lun, line & $
if strcmp(line, 'export ', 7, /fold_case) then begin & $
temp = strsplit(strmid(line, 7), '=', /extract) & $
env = strsplit(temp[1], path_sep(), /extract, count=n) & $
for ienv=0, n-1 do $
if strcmp(env[ienv], '$', 1) then $
env[ienv] = getenv(strmid(env[ienv],1)) & $
if product(strlen(env) gt 0) then $
setenv, temp[0]+'='+strjoin(env, path_sep()) & $
endif & $
endwhile
free_lun, lun

Loading...