Reading System Env with AS3?

In Java we can simply write
System.out.print(System.getenv("ANDROID_SDK_ROOT"));
to read Android SDK install location.

I know such fx like that does not exist in AS3, but how do you do that in AS3?
I already implement via NativeProcess-thing and succeed but if you don’t mind I would like to see your implementation.


var executable:NativeProcess;
var theCMD:NativeProcessStartupInfo=new NativeProcessStartupInfo();
theCMD.executable=new File("C:/Windows/System32/cmd.exe");

if(!executable.running) executable.start(theCMD);
			
executable.standardInput.writeUTFBytes("echo %ANDROID_SDK_ROOT%\n");
			
executable.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,handleCheckEnv);

handler:

function handleCheckEnv(event:ProgressEvent):void
{
			var stdOutput:IDataInput=executable.standardOutput;
          return stdOutput.readUTFBytes(stdOutput.bytesAvailable);
}

I do about the same

little difference is I do it cross-platform detecting the platform with Capabilities.manufacturer

        private function _getPlatform():String
        {
            var platform:String = "";
            var manufacturer:String = Capabilities.manufacturer;
            
            if( (manufacturer != "") && (manufacturer.indexOf( " " ) > -1) )
            {
                var tmp:String = manufacturer.split( " " )[1];
                platform = tmp.toLowerCase();
            }
            else
            {
                platform = manufacturer.toLowerCase();
            }
            
            return platform;
        }

then you can do

            switch( _getPlatform() )
            {
                case "windows":
                filepath = "C:\\Windows\\System32\\cmd.exe";
                args[0] = "/C";
                args[1] = "echo %USERNAME%";
                break;
                
                case "macintosh":
                case "linux":
                filepath = "/bin/sh";
                args[0] = "-c";
                args[1] = "echo $USER";
                break;
            }

and usually it is something called when the AIR app starts during the “boot process”

if I need many environment variables, I just grab them all

Windows

SET

macOS/Linux

printenv

then you can parse line by line on \n and split on = etc.

alternative is to have a Redtamarin little binary that can use getevn() directly
and send the result over socket

a very basic ANE with getenv(), setenv() etc. should be easy to do
but I never had this need yet