2 Replies Latest reply on Oct 4, 2010 8:13 AM by sleblang

    [AIR] Installed App not running NativeProcess

    sleblang Level 1

      I have an AIR app. that is using NativeProcess to run cmd.exe, which in turn runs a .bat file. It works as designed/intended when running in the Flex IDE. However, upon installing and running the AIR app, the process is now longer getting called. From what I can tell, it seems to be stopping when I call nativeProcess.start(npsi). That is no code after this line gets executed.



      Any suggestions on how to resolve this issue?


      Thanks for  any and all replies.



      Below is my code:



           <fx:Script>
                <![CDATA[
                     import mx.controls.Alert;
                     import mx.events.FlexEvent;
      
                     protected var npsi:NativeProcessStartupInfo;
                     protected var nativeProcess:NativeProcess;
                     protected var file:File = new File("C:\\Windows\\System32\\cmd.exe");
                     protected var args:Vector.<String> = new Vector.<String>;
                     
                     protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                     {
                          args.push('filelisting.bat') 
                          
                          npsi = new NativeProcessStartupInfo();
                          npsi.arguments = args;
                          npsi.executable = file;
                          npsi.workingDirectory = File.applicationDirectory.resolvePath("c:\\documents and settings\\DefaultUser\\desktop\\");
                               
                          nativeProcess = new NativeProcess();
                          
                          nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onStandardOutputData);
                          nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onError);
                          nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, exitHandler);
                          
                          nativeProcess.start(npsi); // code no longer is executed when running as an APP;
                          nativeProcess.standardInput.writeUTFBytes(args + "\n");
                          
                     }
                     
                     protected function exitHandler(event:NativeProcessExitEvent):void{
                          Alert.show("Execution Complete");
                          nativeProcess.exit()
                     }
                     
                     private function onError(event:ProgressEvent):void {
                          
                          var process:NativeProcess = event.target as NativeProcess;
                          var data:String = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
                          lbl.text += data;
                          
                          
                     }
      
                     private function onStandardOutputData(event:ProgressEvent):void
                     {
                          var process:NativeProcess = event.target as NativeProcess;
                          var data:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
                          lbl.text += data;
                          
                          !nativeProcess.running
                               nativeProcess.closeInput()
                               
                     }  
      
                ]]>
           </fx:Script>