1

我正在使用 flex4.6,我想从 ma air 应用程序运行一个 .bat 文件,有什么帮助吗?

4

2 回答 2

3

你可以使用NativeProcess类。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/NativeProcess.html

于 2012-11-27T08:30:43.500 回答
2

试试这个

这个类可能对你有帮助 my_command.bat echo "Hello Native Process"

在运行应用程序 (Projectname-app.xml) 之前检查supportedProfiles 标签

桌面扩展桌面移动设备扩展移动设备

扩展桌面

package
{

  import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.ProgressEvent;
import flash.filesystem.File;

import mx.controls.Alert;

public class PlatformPackaging
{
    private var nativeProcess:NativeProcess;
    private var isErrorOccured:Boolean;

    private var batFile:File;
    private var cmdFile:File;

    private function get isWindows():Boolean
    {
        return true;
    }

    public function PlatformPackaging()
    {
    }

    public function start(targetPlatform:String):void
    {
        if(isWindows)
        {
            batFile = File.applicationDirectory.resolvePath("publish/my_command.bat");
            cmdFile = new File("c:\\Windows\\System32\\cmd.exe");
        } 

        proceedToPackaging();
    }


    private function proceedToPackaging():void {

        var processArgs:Vector.<String> = new Vector.<String>;

        processArgs.push("/c");
        processArgs.push(batFile.nativePath);

        var workingDirectory:File = File.applicationDirectory.resolvePath("publish/");
        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

        nativeProcessStartupInfo.arguments = processArgs;
        nativeProcessStartupInfo.executable = cmdFile;
        nativeProcessStartupInfo.workingDirectory = workingDirectory;

        nativeProcess = new NativeProcess();
        nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA,onStandardErrorOutputDataHandler);
        nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onStandardOutputDataHandler);
        nativeProcess.start(nativeProcessStartupInfo);
    }

    private function onStandardErrorOutputDataHandler(event:ProgressEvent) : void
    {
        var certResponse:String = nativeProcess.standardError.readUTFBytes(nativeProcess.standardError.bytesAvailable);

        trace(certResponse);
        nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onStandardOutputDataHandler);
        nativeProcess.exit();
    }

    Alert.show(certResponse,'Error');
}

protected function onStandardOutputDataHandler(event:ProgressEvent):void
{
    var status:String = nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);

    Alert.show(status)
}
 }
}

请让我知道任何澄清。

于 2012-11-28T08:05:44.203 回答