开发者

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

开发者 https://www.devze.com 2023-01-11 03:54 出处:网络
import flash.desktop.NativeProcess; import flash.desktop.NativeProcessStartupInfo; if (NativeProcess.isSupported) {
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.star开发者_JS百科t(npsi);
}

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


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");


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消