as3调用外部应用程序 as调用外部exe文件as3调用bat文件 未测试

本文详细介绍了如何在Flash AS3中调用外部的EXE和BAT文件,通过使用NativeApplication、File、NativeProcessStartupInfo等类实现跨平台的进程调用,包括设置autoExit、resolvePath、start等方法的具体应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值