« 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 | |
| 19,238 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, c, Flex | 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 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 17th, 2010 at 3:55 am
thank you for your share
http://www.christianlouboutinshoes-shop.com
Reply to this comment
March 21st, 2010 at 10:53 pm
welcome to buy mbt healtht shoes
Reply to this comment
March 22nd, 2010 at 9:54 pm
i would say it is wonderful,thanks!
Reply to this comment
March 29th, 2010 at 10:26 pm
welcome to buy wedding dresses
free shipping ,fashion style ,cheaper price
http://www.wedding-dresses-mall.com
Reply to this comment
March 31st, 2010 at 1:45 am
thank you very much ~
Reply to this comment
April 6th, 2010 at 3:34 am
omputer Sciences Corp
Reply to this comment
May 5th, 2011 at 3:07 pm
Does anyone know if it’s possible to use the native process to redirect text to a file using echo? For example, from within AIR send the following to a process:
echo “Just some random text…” > /var/log/random.txt
and have the file /var/log/random.txt created (prompting for super user credentials if necessary)?
Reply to this comment