如何从adobe air应用程序在本地机器上执行.bat文件?

时间:2012-11-27 07:52:38

标签: flex air window adobe

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

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:2)

试试这个

这个类可能对你有用my_command.bat echo“Hello Native Process”

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

桌面扩展桌面移动设备exendedMobileDevice

extendedDesktop

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)
}
 }
}

请让我知道任何澄清。