apache-flexactionscript-3airflash-builder

Launch EXE (Serproxy) with Adobe AIR


I'm developing an AIR application in Flash Builder (Flex) and I needed the option to communicate with a serial port on the computer. So I'm using Serproxy to help me with that.

I want to be able to launch serproxy.exe when my application runs. I've tried two methods, and neither of them are working for me.

I have set supportedProfiles with extendedDesktop.


First method:

var file:File = File.applicationDirectory.resolvePath("assets/serproxy.exe");
file.openWithDefaultApplication();

This proceeds to open the program, but then immediately closes it. No errors are thrown.


Second method:

var file:File = File.applicationDirectory.resolvePath("assets/serproxy.exe");

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var process:NativeProcess = new NativeProcess();

process.start(nativeProcessStartupInfo);

Although through research this method has been found to work, it simply does nothing for me. No errors are thrown, and no program is launched.


If anyone has any ideas please let me know! Thanks


Solution

  • I've solved it. My issue was that since Serproxy opens with cmd.exe, there were some issues keeping the file open, as Windows likes to automatically close it. I got around this by creating a shortcut to the file, and pre-pending its target with

    C:\Windows\System32\cmd.exe /K "C:\...assets\serproxy.exe"
    

    Then I could run the shortcut with

    var file:File = File.applicationDirectory.resolvePath("assets/serproxy.lnk");
    file.openWithDefaultApplication();
    

    And the window stayed open!