« AIR 2.0 Native Installer Concerns | Main | Merry Christmas from AIRVoice (AIR 2.0) »
Adobe AIR: Passing arguments into native executables
| By Rich Tretola | December 15, 2009 | |
| 2,430 views |
I have completed a new chapter for the upcoming O’Reilly Flex 4 Cookbook on AIR Basics. This includes a section on how to work with native executables.
Here is what I did as part of this example.
First I created a simple application that included some native c code that simply accepted a few arguments and printed them to screen. I compiled this c application into an executable on Mac, Windows, and Linux Ubuntu.
I then created an AIR application that included the following snippets of code. Here is what is happening.
When the callNativeApp() method is called, I resolve a path to the NativeApps directory which has been packaged into my application. Then depending on which operating system is running the application, I point the file variable to the proper executable.
Next, I create a NativeProcessStartupInfo object and set the executable property. I also create a Vector of arguments that I set to the NativeProcessStartupInfo’s arguments property. These will be passed into the argc variable of my executable.
Finally, I create an instance of NativeProcess, I add an event listener to listen for ProgressEvent.STANDARD_OUTPUT_DATA, I start the process, and close the input.
The executable will simply look over argc and call printf on each which will then trigger the Progress event and Alert within the AIR application.
ActionScript snippet for this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | private var process:NativeProcess; private function callNativeApp():void{ var file:File = File.applicationDirectory; file = file.resolvePath("NativeApps"); if (Capabilities.os.toLowerCase().indexOf("win") > -1){ file = file.resolvePath("Windows/sample.exe"); } else if (Capabilities.os.toLowerCase().indexOf("mac") > -1) { file = file.resolvePath("Mac/sample"); } else if (Capabilities.os.toLowerCase().indexOf("linux") > -1) { file = file.resolvePath("Linux/sample"); } var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); nativeProcessStartupInfo.executable = file; var args:Vector.<String> = new Vector.<String>(); args.push("Rich Trretola"); args.push("loves"); args.push("Flex & AIR"); nativeProcessStartupInfo.arguments = args; process = new NativeProcess(); process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData); process.start(nativeProcessStartupInfo); process.closeInput(); } private function onStandardOutputData(event:ProgressEvent):void{ Alert.show(process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable)); } |
c Code for this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Here are the results:

This should be enough to wet your appetite.
For the full source code you will have to wait for the book.
Topics: Adobe AIR, Flex, c | 21 Comments »








December 15th, 2009 at 2:28 pm
[...] This post was mentioned on Twitter by Rich Tretola, christian george. christian george said: RT @richtretola Blogged: Adobe AIR: Passing arguments into native executables http://bit.ly/5g3ML7 [...]
December 15th, 2009 at 2:37 pm
Social comments and analytics for this post…
This post was mentioned on Twitter by richtretola: Blogged: Adobe AIR: Passing arguments into native executables http://bit.ly/5g3ML7…
December 16th, 2009 at 4:16 am
[...] Source: http://blog.everythingflex.com/2009/12/15/adobe-air-passing-arguments-into-native-executables/ [...]
December 23rd, 2009 at 2:35 am
chanel handbags
are designed for those women who are in constant pursuit of fashion and beauty,many people fell in love with chanel bags.fashionable, comfortable, reasonable price.
Reply to this comment
December 23rd, 2009 at 10:04 pm
Mbt shoes are physiological footwear. They can improve posture and gait. Welcome to order Mbt Chapa, Mbt walking shoes.
http://www.discountMbt.com
Reply to this comment
January 6th, 2010 at 3:32 am
Mbt enjoy good quality,Mbt Sport and Mbt walking shoes save you up to 81% http://www.mbt-lami.com
Reply to this comment
January 18th, 2010 at 1:59 am
Hi,
Thanks a lot for good tips. I look forward to reading more on the topic in the future. Keep up the good work!
Reply to this comment
January 22nd, 2010 at 3:51 am
Hi,
Thank you for sharing information in the blog. You are really doing a good work. I personally like this blog and appreciates your efforts.
http://www.ukacademia.co.uk
Reply to this comment
January 22nd, 2010 at 4:10 am
Hi,
Thanks for this amazing article. You have shared good insights and experience. It’s an interesting article to read.
Reply to this comment
January 22nd, 2010 at 6:06 am
Hi,
Nice info at this post thanks!!! I really like it.
Reply to this comment
January 22nd, 2010 at 6:09 am
Hi,
It was a very nice article! Just want to say thank you for the information you have shared. Just continue writing this kind of post. Thanks.
http://www.customcoursework.co.uk
Reply to this comment
January 22nd, 2010 at 6:24 am
Hi,
This is really a great stuff for sharing. Keep it up .Thanks for sharing.
Reply to this comment
February 9th, 2010 at 8:57 am
Thanks for the news ^^
I’ve tried to play with that new functionality and a program written in java. Communication of data encoded in UTF works fine in both ways, unfortunately it seems there is a problem when you want to send integers or even bytes in the way AIR -> java (they never reach their destination). Does anybody have the same problem?
Reply to this comment
March 3rd, 2010 at 3:13 am
i love your articles. haha
Reply to this comment
March 4th, 2010 at 5:10 am
the website is good , you are good man ,thank you for your advise , i think you can go to visit the website , it real very good .
cheap jordans
Reply to this comment
March 4th, 2010 at 5:12 am
the website is good , you are good man ,thank you for your advise , i think you can go to visit the website , it real very good .
cheap coogi jeans
Reply to this comment
March 4th, 2010 at 5:14 am
the website is good , you are good man ,thank you for your advise , i think you can go to visit the website , it real very good .
cheap jordan shoes
Reply to this comment
March 7th, 2010 at 4:29 am
think you can go to visit the website , it real very good .
http://www.asics2u.com/asics-gelkinsei-2-c-12.html
Reply to this comment
March 7th, 2010 at 10:28 pm
Five fingers?vibram shoes are very comfortable.And if you wear it to do some ourdoor sport,it will make you relex and spirit!
vibram
vibram five fingers
vibram shoes
Reply to this comment
March 11th, 2010 at 8:23 am
Hi Rich,
Nice tutorial out there.I am stuck in a little logic problem.
I have made an application in Windows for xml to swf generation using swfmill and native process of AIR 2.Now I have to implement the same for Linux also.
Could you just hint me on what to do?Further if I make this application does it work on all variation of Linux.
Thanks in advance
Reply to this comment
March 15th, 2010 at 3:22 am
native process of AIR 2.Now I have to implement the same for Linux also.
Could you just hint me on what to do?Further if I make this application does it work on all variation of Linux.
Reply to this comment