Enviromnent variables

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Enviromnent variables

Postby alexeyv on Sat Mar 04, 2017 10:39 am

How can one read system environment variable in a portable way?
For example in Python I can write
Code: Select all
import os
os.getenv('HOME')

in Common Lisp (at least in CCL or LW) I can call
Code: Select all
(getenv 'HOME')

In Dyalog I was not able to find anything in documentation. I currently used
Code: Select all
⎕SH 'echo $HOME'

but it doesn't look portable :\
alexeyv
 
Posts: 56
Joined: Tue Nov 17, 2015 4:18 pm

Re: Enviromnent variables

Postby Morten|Dyalog on Sat Mar 04, 2017 11:43 am

Try this:

Code: Select all
⎕←2 ⎕NQ '.' 'GetEnvironment' 'HOME'


It isn't EXACTLY the same, in that - under Windows - it will also look on the command line for a switch called HOME, then in the environment, and finally in the Windows Registry, but for writing portable applications it tends to be what you want.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: Enviromnent variables

Postby alexeyv on Sat Mar 04, 2017 1:22 pm

Thanks! This works (I'm trying on OSX).

I think something like ⎕ENV could be more intuitive though.
alexeyv
 
Posts: 56
Joined: Tue Nov 17, 2015 4:18 pm


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest