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...
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With