private function callTest(event: Event): void{callExe("d:/a.exe");callBat("d:/a.bat");} private function callExe(extUrl: String): void{//使用静态属性 NativeApplication.nativeApplication 获取应用程序的 NativeApplication 实例//指定在关闭所有窗口后是否应自动终止应用程序。 NativeApplication.nativeApplication.autoExit = true;//调用的文件var file: File = new File();file = file.resolvePath(extUrl);var nativeProcessStartupInfo: NativeProcessStartupInfo = new NativeProcessStartupInfo();nativeProcessStartupInfo.executable = file;var process: NativeProcess = new NativeProcess();process.start(nativeProcessStartupInfo);} public static function callBat(batUrl: String): void{//调用bat文件var exePath: String = "C:/Windows/system32/cmd.exe"; //cmd的路径var info: NativeProcessStartupInfo = new NativeProcessStartupInfo(); //启动参数info.executable = new File(exePath);//参数var processArg: Vector.<<span style="color:#2aa198;font-weight:bold;">String> = new Vector.<<span style="color:#2aa198;font-weight:bold;">String>();processArg[0] = "/c"; //加上/c,是cmd的参数processArg[1] = batUrl; //bat的路径info.arguments = processArg;//执行var process: NativeProcess = new NativeProcess();process.addEventListener(NativeProcessExitEvent.EXIT, packageOverHandler);process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, outputHandler);process.start(info);} private static function outputHandler(event: ProgressEvent): void{trace("outputHandler");} private static function packageOverHandler(event: NativeProcessExitEvent): void{trace("packageOverHandler event: NativeProcessExitEvent");} http://blog.sina.com.cn/s/blog_73bed4520102w69z.html
原文地址:https://www.cnblogs.com/dt1991/p/10336936.html
时间: 2024-10-09 13:05:29