如何运行“ipconfig”并在windows中的adobe AIR中获取输出?

问题描述 投票:0回答:4
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);
}

以上只能运行子应用程序,但如何运行像ipconfig这样的独立应用程序(命令)并得到结果?

windows flash actionscript-3 actionscript air
4个回答
3
投票

你实际上可以刮掉STDOUT和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));
}

更多信息:http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b060d22f991220f00ad8a-8000.html

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

编辑:实现也许您的问题也是如何启动外部应用程序?这是一个如何在OSX中运行'top'的示例:

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

0
投票

如果您需要网络配置信息,可以使用NetworkInfo.networkInfo.findInterfaces()。将为您节省与其他流程交互的麻烦,并且它也是可移植的。

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


0
投票

如果要在不知道它位于何处的情况下运行ipconfig.exe,可以运行带参数“/ C”“ipconfig.exe ...”的cmd.exe。当然,这需要知道cmd.exe在哪里。我刚把它包含在我的AIR应用程序(Windows版本)中。


0
投票

我不认为你可以,它是NativeProcess API的自我限制。但是,您可以自己创建一个小的Windows二进制文件,调用ipconfig并将信息传递回AIR应用程序。

如果创建这个二进制文件看起来很重要,请查看HaxexCross,您可以使用与ActionScript非常相似的语言来完成它。

© www.soinside.com 2019 - 2024. All rights reserved.