HI - Mac OS X environment variable problem here. When I enter the following:
Dim s As String
s = System.EnvironmentVariable("HOME")
Under Variables I get: s /Users/rattus
when I enter:
Dim computerName As String
computerName = System.EnvironmentVariable("HOST")
I get nothing.
Querying either one in Mac OS X Terminal gets the proper answer.
What is the difference between environment variable handling between HOST and HOME?
I haven’t tried Linux yet for the same.
Xojo 2017.2, Mac OS X 10.12.6
There are two independent sets of variable on the Mac, accessed through
env commands in the terminal.
env set does not contain a var named “HOST”. The
set set includes a var named “HOSTNAME”.
You’ll need to manually shell to the system to retrieve the variables, then search for your specific string.
Try this in a Window.Open event to see what vars are available.
dim sh as new Shell
sh.Execute("set") // try "env" to see the difference
TextArea1.Text = sh.Result
Its alsi worth noting that System.Environment is not initialized the same way when you double-click an app as when you open a terminal window. The environment for a terminal is typically with more detail as to make command-line calls a little easier.
Just call “/bin/hostname”. No need to fiddle around with “env” or “set” output
BTW: On Mac there is no shell call needed. Just use
[code] Declare Function NSClassFromString Lib “Cocoa” (aClassName As CFStringRef) As Ptr
Declare Function processInfo lib “Cocoa” selector “processInfo” (obj_id as Ptr) as Ptr
Declare Function hostName lib “Cocoa” selector “hostName” (obj_id as Ptr) as CFStringRef
dim pi as Ptr = NSClassFromString(“NSProcessInfo”)
dim info as Ptr = processInfo(pi)
dim s as CFStringRef = hostName(info)[/code]