AIR NativeProcess standardInput not connecting to application

I am writing an AIR application that launches a C # console application and they need to communicate. I would like to use standard input / standard output for this, but I can't get it to work.

When a C # application receives input from standard input, it must send it back through standard output, and if it receives "output", then it quits. I can verify this from the command line and it works correctly. When I send a string from AIR, I get no response from a C # application.

I send an argument when the C # application starts, and I get a response from this, so my AIR application, at least, can receive messages from standard output, it's just standard input that doesn't work. When I send a message from AIR via standardInput, I get a progress event with byte Loaded = 3 when I send the key code, and bytesLoaded = 5 when I send the "exit" command.

Here is the C # code:

static void Main(string[] args) { if (args.Length > 0) { Console.WriteLine(args[0]); } while (true) { string incoming = Console.ReadLine(); string outgoing = "received: " + incoming; Console.WriteLine(outgoing); if (incoming == "exit") return; } } 

And here is the AS3 code:

 private function init(e:Event=null):void { this.removeEventListener(Event.ADDED_TO_STAGE, init); NativeApplication.nativeApplication.addEventListener(Event.EXITING, onAppClose); var info:NativeProcessStartupInfo = new NativeProcessStartupInfo(); var file:File = File.applicationDirectory.resolvePath("test.exe"); info.executable = file; process = new NativeProcess(); info.arguments.push("native process started"); process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData); process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData); process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, onInputProgress); process.addEventListener(Event.STANDARD_OUTPUT_CLOSE, onOutputClose); process.addEventListener(Event.STANDARD_ERROR_CLOSE, onErrorClose); process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError); process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onIOError); process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError); stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp); process.start(info); } private function onKeyUp(e:KeyboardEvent):void { if (e.keyCode == Keyboard.ESCAPE) process.standardInput.writeUTFBytes("exit\n"); else { var msg:String = e.keyCode + "\n"; process.standardInput.writeUTFBytes(msg); } } private function onOutputData(e:ProgressEvent):void { var data:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable); trace("Got: ", data); } 
+6
source share
1 answer

I ran into this problem a few months ago, but I never resolved it because I used command line arguments instead. I just returned to him, although I really want to know what is happening.

Now I have found that targeting with .NET 3.5 or earlier makes it work as expected for me. Go back to version 4.0 and I get nothing from stdin. I'm not quite sure where the problem is, but if you can get around v3.5, then this may be the solution for you.

+4
source

All Articles