views:

84

answers:

2

Hi, I would like to execute a CMD command from my flex application programmatically. Something like

> mediaplayer.exe "mySong.mp3"

I also tried using fscommand but was not successful. While googling I learnt that its not supported by AIR. I would like to know if there is any other alternative for executing the commands. Thanks...

+2  A: 

It is supported by AIR 2.0, see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/NativeProcess.html

Also, you should deploy your application not as an .air file, but as a native installer in order to NativeProcess to work (with adt console tool from AIR SDK). There are several gotchas on the way, but it can be done. In development, you can test out NativeProcess easily.

alxx
Here is an app that will convert an .air file to a native installer: http://www.webkitchen.be/package-assistant-pro/
John Isaacks
+2  A: 

You need to use NativeProcess which is only available in AIR 2.0+

This should do the trick:

if(NativeProcess.isSupported)
{
    var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

    var mp:File = new File();
    mp = mp.resolvePath('native\path\to\mediaplayer.exe');

    nativeProcessStartupInfo.executable = mp;

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

    args.push('mySong.mp3');

    nativeProcessStartupInfo.arguments = args;

    var process:NativeProcess = new NativeProcess();

    process.start(nativeProcessStartupInfo);

}

Also make sure your app.xml file contains this:

<supportedProfiles>extendedDesktop</supportedProfiles>
John Isaacks
Thanks Alxx and John. Both the answers have helped me actually. But I could accept only one. :(@John: The app is working only when 'extendedDesktop' is alone in the node. Giving it along with 'desktop' is throwing 'not supported in current profile error'.
Goje87
@Goje87 thanks for the feedback, I updated my answer to reflect that.
John Isaacks