1 Reply Latest reply on Dec 5, 2012 11:17 AM by roymeo_

    Adobe AIR 2.0 Problems communicating with Native Process

    rohithtap

      Hi

      I am new to actionscript programming and AIR applications. I am trying to communicate with an external .exe, 'ngspice.exe' the ngspice application in windows operating system. I am able to open the application but when I try writing to the standard input stream, I don't see the program responding the data send to the input stream . Also when I run a simulation using the interface provided by the application itself, I am not able to recieve any responses when I try to trace from the standard output stream of the process. But when I exit the program, the event listener is working and traces the output of the code with which the application exited. I want to provide spice with netlist and commands from my AIR app and have the outputs from spice received back on my app. The code that I am using is as follow:

       

           import flash.desktop.*;

           import flash.events.*;

           import flash.filesystem.*;

            

           var process:NativeProcess;

       

           if(NativeProcess.isSupported){

                               setupAndLaunch();

           }

           else

           {

                     trace("NativeProcess not supported.");

           }

           

          

           function setupAndLaunch():void

           {

                var executablePath:String="C:/Spice/bin/ngspice.exe";

                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();    

                var file:File=new File(String(executablePath));

                var args:Vector.<String> = new Vector.<String>();

                //This parameter is to open ngspice in pipe mode

                var parametersString:String="-p";

                     var parameters:Array;

                     parameters = parametersString.split(" ");

                for each(var parameter:String in parameters){

                               args.push(parameter);

                     }

                trace(args);

                nativeProcessStartupInfo.executable=file;

                     nativeProcessStartupInfo.arguments = args;

       

                     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);

                     process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onIOError);

                     process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, standardInputProgress);

            

                //why isn't the following line working??

                     process.standardInput.writeUTF("run");

       

           }

          

            function standardInputProgress(evt:ProgressEvent):void

                {

                          trace("standardInputProgress");

                }

       

                function onOutputData(event:ProgressEvent):void

                {

                          trace("Got:",process.standardOutput.readUTFBytes(process.standardOutput.bytesAv ailable));

       

                }

       

                function onErrorData(event:ProgressEvent):void

                {

                          trace("ERROR -",process.standardError.readUTFBytes(process.standardError.bytesAvailable));

       

                }

       

                function onExit(event:NativeProcessExitEvent):void

                {

                          trace("Process exited with ",event.exitCode);

                }

       

                function onIOError(event:IOErrorEvent):void

                {

                          trace(event.toString());

                }

       

       

      Please help me out.

      Thanks in advance