2013-05-14 37 views
0

我需要使用NativeProcess进行一些非常简单的操作,我需要通过cmd行启动一个.exe文件并将其传递给一个参数。我发现了NativeProcess示例,但它们都是用于更复杂的事情,并没有显示完整的实现。我在flash as3方面有很多经验,但在这个特定领域没有......如果有人能告诉我这是从开始到结束如何实现的,我将不胜感激。如何在Air应用程序中实现NativeProcess

+0

http://gotoandlearn.com/play.php?id=125 - 这是一个很好的起点。 – Tox 2015-05-18 16:45:37

回答

2

下面是代码从Adobe网站对究竟在做什么你问:

package 
{ 
    public class Main extends Sprite 
    { 
     public var process:NativeProcess; 

     public function Main() 
     { 
      if(NativeProcess.isSupported) 
       setupAndLaunch(); 
      else 
       trace("NativeProcess not supported."); 
     } 

     public function setupAndLaunch():void 
     {  
      var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); 
      var file:File = File.applicationDirectory.resolvePath("yourapp.exe"); 
      nativeProcessStartupInfo.executable = file; 

      var processArgs:Vector.<String> = new Vector.<String>(); 
      processArgs[0] = "the parameter you are passing"; 
      nativeProcessStartupInfo.arguments = processArgs; 

      process = new NativeProcess(); 
      process.start(nativeProcessStartupInfo); 
      process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData); 
      process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData); 
      process.addEventListener(NativeProcessExitEvent.EXIT, onExit); 
      process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError); 
      process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError); 
     } 

     public function onOutputData(event:ProgressEvent):void 
     { 
      trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable)); 
     } 

     public function onErrorData(event:ProgressEvent):void 
     { 
      trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable)); 
     } 

     public function onExit(event:NativeProcessExitEvent):void 
     { 
      trace("Process exited with ", event.exitCode); 
     } 

     public function onIOError(event:IOErrorEvent):void 
     { 
      trace(event.toString()); 
     } 
    } 
} 

和重要信息The NativeProcess class and its capabilities are only available to AIR applications installed with a native installer (extended desktop profile applications). When debugging, you can pass the -profile extendedDesktop argument to ADL to enable the NativeProcess functionality. At runtime, you can check the NativeProcess.isSupported property to to determine whether native process communication is supported.

我测试在Flash上​​面通过设置应用程序配置文件制定到Extended Desktop和它的工作原理。

更多信息here