OS Env variables
Posted
#1
(In Topic #1331)
Regular

Is it possible to access O.S Environment like $PATH, $UID and all exported linux variables ?
Posted
Regular

First, there is no such thing as the operating system environment. "Environment" refers to the shell in use, whether that is actual or implied. Now, it is possible that when a program is invoked under init (or whatever the thing that systemd :? uses and who cares anyway) it will do so in a new shell, which may have its own environment.
Second, Application.Env returns the environment for the process executed by the Gambas runtime. Caveat: This may be different when the project is run inside the IDE compared to when the executable archive is run outside the IDE. On the other hand, the Env class (member of the "gb" component) should (I believe) return the login shell component. (Unless, there is another shell between the login and thee current process. Clear eh?
Thirdly, the example items you have used are shell variables, not particularly environment variables. For example UID is a shell variable exposed by the bash shell. There may not be an environment variable matching that name. Unusual, but also possible is a shell may run without a PATH variable being set in its environment. Also the variables are not "linux" variables, the kernel variables are an entirely different kettle of fishoids. See The kernel’s command-line parameters - The Linux Kernel documentation for a list.
So maybe try to explain what you are trying to achieve.
Posted
Regular

I want to Read $PATH, or any variable exported to the linux system.
One way, is to use "SHELL" reading the var with an echo.
/lang/shell - Gambas Documentation
Posted
Guru

the wiki about Application.Env /comp/gb/application/env - Gambas Documentation even shows PATH as an example.
Env[] is the same as Application.Env[]
Did you not see that?
Posted
Guru

sergioabreu said
Application.Env seems to work with parameters related with the app command line.
Where did you read that?
you are incorrect
wiki says
Returns a virtual collection of strings containing the process environment variables.
Posted
Regular

So the simple answer was: Use ENV instead of Application.Env
That's why I tried shell, I didn't have tested Env["PATH"]
Cheers
Posted
Regular

BruceSteers said
Where did you read that?
you are incorrect
wiki says
Returns a virtual collection of strings containing the process environment variables.
You are too quick to fight man. You know the meaning of the word "SEEMS" ?
It was just what I found out, and by the way, the process environment variables are ALSO the ones passed via command line.
Cheers
Posted
Guru

I'm never wrong said
So the simple answer was: Use ENV instead of Application.Env
That's why I tried shell, I didn't have tested Env["PATH"]
No, not the answer at all.
Env[] is exactly the same as Application.Env[]
Env["PATH"] and Application.Env["PATH"] would give the exact same result.
so had you not tested Application.Env["PATH"] also?
And i am not fighting, i just corrected you….
Bruce said
Where did you read that?
you are incorrect
wiki says
Returns a virtual collection of strings containing the process environment variables.
Hardly fighting words. besides it seems you're the one being rude with all bold text digs at people who are trying to help you.
(i see you edited some of your posts to seem less like an ass though)
seems your big ego is taking a hit.
seems the truth hurts when you are living a lie.
seems I DO know what seems means.
1 guest and 0 members have just viewed this.


