views:

89

answers:

1

Hi

I want to run an .exe file from my Flash/Flex/AIR Application, How is it possible?

What I need is to build an Interface to open a xls file and convert it into swf, I have the converter file which is an exe file, when I run convert.exe infile.xls outFile.swf. once the conversion is done, I need to show all swfs inside my Application.

I know Action Script 3.0.

+4  A: 

I think this may be done with AIR since 2.0 version using NativeProcess. I don't know if you can run a .exe file (because of the security issues) but I know you can run python scripts (I've done it) so you can make a python script who calls your .exe file

Here is the (commented) example from the Help of NativeProcess:

// ...
// package and imports declarations
// ...

public class NativeProcessExample extends Sprite
{
    // this is the process
    public var process:NativeProcess;

    public function NativeProcessExample()
    {
        // we have to know if we can run NativeProcess
        if(NativeProcess.isSupported)
            setupAndLaunch();
        else
            trace("NativeProcess not supported.");
    }

    public function setupAndLaunch():void
    {     
        // we create a NativeProcessStartupInfo, this will tell the what process do you want to run
        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        var file:File = File.applicationDirectory.resolvePath("test.py");
        nativeProcessStartupInfo.executable = file;

        // now create the arguments Vector to pass it to the executable file
        var processArgs:Vector.<String> = new Vector.<String>();
        processArgs[0] = "foo";
        nativeProcessStartupInfo.arguments = processArgs;

        // create the process
        process = new NativeProcess();

        // listen to events for I/O and Errors
        process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
        process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
        process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
        process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
        process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);

        // run it!
        process.start(nativeProcessStartupInfo);
    }

    // event handlers
    public function onOutputData(event:ProgressEvent):void
    {
        trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable)); 
    }

    public function onErrorData(event:ProgressEvent):void
    {
        trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable)); 
    }

    public function onExit(event:NativeProcessExitEvent):void
    {
        trace("Process exited with ", event.exitCode);
    }

    public function onIOError(event:IOErrorEvent):void
    {
         trace(event.toString());
    }
}

I hope this helps

unkiwii
you can run .exe files, you just can't run .bat files. also, in order to use NativeProcess the .air installer has to be converted into a native installer (.exe, .dmg, etc.), which can be accomplished by using ADT.
TheDarkInI1978