原文链接: http://sswilliam.blog.163.com/blog/static/189696383201181910955840/
发现很多人还是受这个问题困扰的。也难怪,AIR的文档确实有bug
NativeProcess的文档里说明,NativeProcess在windows下只能调用exe。在mac下只能调用dmg。所以,直接把.bat的路径传入nativeProcess的参数中肯定是不行的。而且NativeProcess直接传入.py文件就执行python经过测试也是不行的。应该是文档的一个bug。那么,怎么调用bat文件呢?
解决方案是用NativeProcess调用cmd.exe,然后将bat的路径以参数传入cmd.exe。这样就可以通过cmd来执行bat了。具体做法如下:
var exePath:String = "C:/Windows/system32/cmd.exe";//exe路径,经过测试,直接从system32下复制到程序的目录下也是没有问题的,前提是你的程序都是默认安装的。环境变量也没变
var shellPath = "C:/test.bat"
var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();//启动参数
info.executable = new File(exePath);
var processArg:Vector.<String> = new Vector.<String>();
processArg[0] = "/c";//加上/c,是cmd的参数
processArg[1] = shellPath;//shellPath是你的bat的路径,建议用绝对路径,如果是相对的,可以用File转一下
info.argument= processArg;
var process:NativeProcess = new NativeProcess();
process.addEventListener(NativeProcessExitEvent.EXIT,packageOverHandler);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,outputHandler);
process.start(info);
Python原理也一样,只不过是调用python.exe。如果需要绿色化python。参考前面的博文
http://sswilliam.blog.163.com/blog/static/1896963832011621102112679/