NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't Access Environment Variables from LabVIEW on RT Target

I've created a custom environment variable for the lvuser (i.e. MYPATH=/tmp/mydir). Now I want my LabVIEW application to read this environment variable, but when I use the System Exec.vi to call "echo $MYPATH", it returns blank. If I ssh into the RT, su to lvuser, and type the same thing, I get what I expect. What is the issue with doing this from the System Exec.vi in LabVIEW?

 

UPDATE 2/12/2024:
I created a VirtualBox with NI Linux RT (https://www.youtube.com/watch?v=s15gM5b635M) to continue testing this issue while the PXI is unavailable, and I am able to see the environment variable in the virtual machine just fine. So, I will have to continue investigating why I cannot get the same behavior from the embedded PXIe-8880 controller.

 

 

0 Kudos
Message 1 of 6
(394 Views)

I don't have access to an LV RT instance to verify it for myself... Is there a chance that the shell in which your environment variable was declared is not the same one used by LV's System Exec call?

 

0 Kudos
Message 2 of 6
(358 Views)

@Dhakkan wrote:

I don't have access to an LV RT instance to verify it for myself... Is there a chance that the shell in which your environment variable was declared is not the same one used by LV's System Exec call?

 


As someone who does a fair amount on Linux ( not RT just general Linux) this is most likely the problem. That or it is running as a different user.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 3 of 6
(350 Views)

Actually right after I hit send I seem to recall - don’t try progams run as lvuser or something. When you ssh are you logging in as lvuser - if so then that may be your problem. 

intsead of env variables you could try storing it in a file - although you have be careful about permissions and iirc lvrt programs run in some kind of chroot?  So you’ll have to make sure your lvrt program can find it.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 4 of 6
(348 Views)

Thank you for the reply Taggart. I have been logging in as admin, then su lvuser to ensure the environment variable is set for lvuser.

 

Also, yes, the LV program runs as lvuser. I can use the System Exec.vi to run, "whoami" and it returns "lvuser".

Interestingly, running "env" through System Exec.vi yields a very small subset of the lvuser's environment variables. Basically, just PWD which has the value of the directory in which the LV program is stored, and SHLVL which equals 1. Perhaps this is why the environment variable is not accessible because the program is running in a lower level shell where the profile has not been updated?

 

Unfortunately, it seems like I will have to store the variable in a file.

0 Kudos
Message 5 of 6
(321 Views)

@BrantZ wrote:

Interestingly, running "env" through System Exec.vi yields a very small subset of the lvuser's environment variables. Basically, just PWD which has the value of the directory in which the LV program is stored, and SHLVL which equals 1. Perhaps this is why the environment variable is not accessible because the program is running in a lower level shell where the profile has not been updated?


Does it not even include SHELL, to indicate what shell is being used?

 


@BrantZ wrote:

Unfortunately, it seems like I will have to store the variable in a file.


Perhaps you could try one more thing before resorting to a file approach - set the value at a system level in the /etc/ folder. There are multiple options, the following two links can give you a gist:

man environment.d

unix.stackexchange

NOTE: You may wish to use the man pages of the actual environment, rather than the generic one above.

0 Kudos
Message 6 of 6
(309 Views)