Posts Tagged ‘air.NativeProcess’

Launching a Mono/.NET exe from Adobe Air

I’m working on some bridging code between Adobe Air and Mono/.NET stuff. The first challenge in the process was figuring out how the launch the .exe from Adobe Air. In Windows you can just launch the .exe file (assuming the .NET Framework is installed), but for other system you need to pass it as an argument to the mono executable. The JavaScript code is shown below.

var proc = new air.NativeProcess();
if
(air.Capabilities.os.toLowerCase().indexOf("win") > -1) {
    
var file = air.File.applicationDirectory;
    file = file.resolvePath(
"air.SocketBridgeServer.exe");
                            
    
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
    nativeProcessStartupInfo.executable = file;

    proc.start(nativeProcessStartupInfo);
}
else {
    
var mono = new air.File();
    mono = mono.resolvePath(
"/usr/bin/mono");
                            
    
var exeFile = air.File.applicationDirectory;
    exeFile = exeFile.resolvePath(
"air.SocketBridgeServer.exe");
                            
    
var args = new air.Vector["<String>"];
    args.push(exeFile.nativePath);
                            
    
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
    nativeProcessStartupInfo.executable = mono;
    nativeProcessStartupInfo.arguments = args;
    proc.start(nativeProcessStartupInfo);
}

This handles Windows, OS X, and should handle most distros of Linux; the location of the mono executable is the tricky part, Adobe Air doesn’t read the path environment variable, so the exact location of mono must be specified. mono is usually in /usr/bin, but custom distros, installations, etc. could put it elsewhere.