libnet
libnet

Reputation: 45

How to run "ipconfig" and get the output in adobe AIR in windows?

import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;

if (NativeProcess.isSupported) {
    var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    var processpath:File = File.applicationDirectory.resolvePath("MyApplication.whatever");
    var process:NativeProcess = new NativeProcess();

    npsi.executable = processpath;
    process.start(npsi);
}

The above can only run a sub-application, but how to run an independent application(command) like ipconfig and get the result?

Upvotes: 0

Views: 1131

Answers (4)

Juan Delgado
Juan Delgado

Reputation: 2030

I don't think you can, it's a self-impossed limitation of the NativeProcess API. However, you can create a little Windows binary yourself that calls ipconfig and passes the information back to the AIR app.

If creating that binary seems like a big deal, take a look to Haxe and xCross, you can get it done with a fairly similar language to ActionScript.

Upvotes: 0

alxx
alxx

Reputation: 9897

If you want to run ipconfig.exe without knowing where it is located, you can run cmd.exe with arguments "/C" "ipconfig.exe ...". Of course, this requires to know where is cmd.exe. I had just included it with my AIR app (windows version).

Upvotes: 0

kichik
kichik

Reputation: 34744

If you need network configuration information, you could use NetworkInfo.networkInfo.findInterfaces(). Will save you the trouble of interacting with another process and it's also portable.

http://help.adobe.com/en_US/air/reference/html/flash/net/NetworkInfo.html

Upvotes: 0

dain
dain

Reputation: 6699

You in fact can scrape STDOUT and STDERR:

process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onError);
process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);

public function onError(event:ProgressEvent):void
{
    trace(event);
    trace(process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}

public function inputProgressListener(event:ProgressEvent):void
{
    process.closeInput();
}

public function onOutputData(event:ProgressEvent):void
{
    trace(event);
    trace(process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}

More info at: http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b060d22f991220f00ad8a-8000.html

And: http://www.as3offcuts.com/2010/08/air-2-native-process-example-mouse-screen-position/

Edit: realised maybe your question is also how to launch an external application? Here's an example how to run 'top' in OSX:

npsi.executable = new File("/usr/bin/top");

Upvotes: 3

Related Questions