如何运行的Flash / Flex的/ AIR一个EXE文件?文件、Flex、Flash、EXE

2023-09-08 14:13:11 作者:烈酒烧喉

我想从我的Flash / Flex的/ AIR应用程序运行.exe文件,这怎么可能?

我需要的是建立一个接口,打开一个xls文件,并转换成SWF,我这是一个exe文件转换器的文件,当我运行 CONVERT.EXE infile.xls不过outFile。 SWF 。 一旦转换完成后,我需要证明我的应用程序内的所有主权财富基金。

我知道动作脚本3.0。

解决方案

我想这可能与AIR自2.0版本使用来完成的NativeProcess.我不知道你是否能运行(因为安全问题)的.exe文件,但我知道你可以运行Python脚本(我已经做到了),这样就可以让谁调用你的.exe文件

下面是从NativeProcess:

  // ...
//包,进口报关
// ...

公共类NativeProcessExample扩展Sprite
{
    //这是过程
    公共变种过程:的NativeProcess;

    公共职能NativeProcessExample()
    {
        //我们知道,如果我们可以运行的NativeProcess
        如果(NativeProcess.isSupported)
            setupAndLaunch();
        其他
            跟踪(不支持的NativeProcess。);
    }

    公共职能setupAndLaunch():无效
    {
        //我们创建一个NativeProcessStartupInfo,这会告诉你要运行什么进程
        VAR nativeProcessStartupInfo:NativeProcessStartupInfo =新NativeProcessStartupInfo();
        var文件:文件= File.applicationDirectory.resolvePath(test.py);
        nativeProcessStartupInfo.executable =文件;

        //现在创建的参数向量将它传递给可执行文件
        VAR processArgs:矢量<串GT。 =新矢量<串GT;();
        processArgs [0] =富;
        nativeProcessStartupInfo.arguments = processArgs;

        //创建进程
        流程=新的NativeProcess();

        //听的I / O和错误事件
        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);

        // 运行!
        的Process.Start(nativeProcessStartupInfo);
    }

    //事件处理程序
    公共职能onOutputData(事件:ProgressEvent):无效
    {
        跟踪(得到,process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
    }

    公共职能onErrorData(事件:ProgressEvent):无效
    {
        跟踪(错误 - ,process.standardError.readUTFBytes(process.standardError.bytesAvailable));
    }

    公共职能onExit(事件:NativeProcessExitEvent):无效
    {
        跟踪(过程与退出,event.exit code);
    }

    公共职能onIOError(事件:IOErrorEvent):无效
    {
         跟踪(event.toString());
    }
}
 

我希望这有助于

我的电脑一部分exe文件打不开了,怎么办

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.

解决方案

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