exporting environment variables for use by Dyalog

For Raspberry Pi specific issues .. more general issues will appear in UNIX and Linux

exporting environment variables for use by Dyalog

Postby ray on Sat Apr 20, 2019 1:03 pm

I wish to turn a debugging feature used within Dyalog APL on and off from the Raspberry Pi command line before I start running APL.

I thought I could on the command line:
Code: Select all
pi@raspberrypi:~ $ export DEBUGANT=1

which appears to work because
Code: Select all
pi@raspberrypi:~ echo $DEBUGANT
1


So I thought from within the APL session I could read $DEBUGANT thus
Code: Select all
 a← ⎕SH'echo $DEBUGANT'

unfortunately "a" did not contain what I expected:
Code: Select all
 a≡(,⊂'') 
1


Can someone tell me where I am going wrong, and how to correctly set up an environment variable and then read in in Dyalog APL..

Thanks
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: exporting environment variables for use by Dyalog

Postby AndyS|Dyalog on Tue Apr 23, 2019 8:25 am

Hi Ray

You should find that

export DEBUGANT=1
/opt/mdyalog/17.1/32/unicode/mapl
⎕sh'echo $DEBUGANT'
should work, as should

⊣2⎕nq'.' 'GetEnvironment' 'DEBUGANT'
this last one is rather quicker than calling ⎕SH.

You can also use
DEBUGANT=1 /opt/mdyalog/17.1/32/unicode/mapl

For setting DEBUGANT on a more permanent basis, you can always add
export DEBUGANT=1
to $HOME/.dyalog/dyalog.config
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm

Re: exporting environment variables for use by Dyalog

Postby ray on Tue Apr 23, 2019 2:42 pm

Thanks Andy

I have now found the reason that I am having problems with my $DEBUGANT exported variable from within my APL session, it is because I export it as "pi" but am running APL as "root".

I know it is not recommend running Dyalog on the RPI as "root" but (so far) I have not found any way around this. I need ROOT privileges to access certain aspects of the GPIO pins used by C programs accessed via ⎕NA calls. Hence, I have to start APL from "root" and not "pi".

Then when I try from within APL to access $DEBUGANT, it is not found in the "root" environment!

As Andy suggests, (when I run APL as "pi") I have no problem accessing $DEBUGANT.

As an aside Andy, is Dyalog version 17.1 (and for that matter RIDE 4.2) available to us "mere mortals" yet? You have mentioned both in recent replies to my queries!
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: exporting environment variables for use by Dyalog

Postby AndyS|Dyalog on Wed Apr 24, 2019 7:58 am

Hi Ray

I suspect that you're calling something like
Code: Select all
sudo /opt/mdyalog/17.0/32/unicode/mapl
in which case you have to work a bit (lot) harder to get your environment variable into your APL process.

If you
Code: Select all
sudo visudo
and add
Code: Select all
Defaults env_keep += "DEBUGANT"
and then call
Code: Select all
sudo DEBUGANT=1 /opt/mdyalog/17.0/32/unicode/mapl
that should get you what you want. I only know this as I needed it for running part of the QAs as root; you may be able to tighten it down further if you want/need to.

What you may like to try is to
Code: Select all
sudo DEBUGANT=1 /opt/mdyalog/17.0/32/unicode/mapl
then initialise the ⎕NA calls and then call
      4007⌶'ray'
so that your process continues to run with ray's privileges. Note that 4007⌶ can only be called once in a process, and only works on non-Windows platforms. We implemented this for several reasons, the most important being that when you start a web server and you want to bind to port 80 (or indeed any port less than 1024) then you must do so with a process with root privileges, but once you've bound to the port, you want to run as a normal user. Not entirely sure whether this will work for you but it might be worth a try. FWIW you can compare ⊃⎕ai and ⎕an to see what your effective and real userids are.

17.1 is still just around the corner; we're making some changes to new extensions to the HTMLRenderer. 17.1 will come bundled with RIDE 4.2, but we also encourage people to download RIDE from Github; there is no difference in functionality between what's on GitHub and what appears in an installation image. I would recommend however always taking the release marked as "Latest Release" rather than marked as "Draft".
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm

Re: exporting environment variables for use by Dyalog

Postby ray on Thu Apr 25, 2019 11:43 am

Hi Andy

Thank you for a most useful and informative reply. I was also totally unaware of visudo and have been investigating it further via google.

I have a script to start up Dyalog APL on the pi which includes the extra command to allow remote access to the session via Ride.

I will have fun playing with my new knowledge.

Thanks again
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 1 guest