Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute CMD commands in flex using actionscript?

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...

like image 836
Goje87 Avatar asked Apr 20 '26 04:04

Goje87


2 Answers

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>
like image 112
JD Isaacks Avatar answered Apr 23 '26 14:04

JD Isaacks


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.

like image 25
alxx Avatar answered Apr 23 '26 15:04

alxx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!